JSPM

toffeescript-coroutines

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q20623F
  • License ISC

Coroutines in ToffeeScript

Package Exports

  • toffeescript-coroutines

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (toffeescript-coroutines) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Coroutines in ToffeeScript

A simple coroutine construct over ToffeeScript's Continuation Passing Style Transform

{pause, wait, update} = require 'coroutines.coffee'

setInterval update, 1000 / 60  #  run the scheduler
#requestAnimationFrame update


it_pauses = ->
    loop
        do somethingEveryFrame

        pause!  #  continue in next frame


it_waits = ->
    loop
        for thing in things
            do thing.action

            wait! 100  #  continue after 100 milliseconds


it_flows = ->

    #  a coro that can optionally be waited on by another
    one = (nxt) ->
        wait! 1000
        console.log 'one'
        nxt?()

    two = ->
        one!  #  wait for one to finish

        console.log 'two'

    do two  #  after a second, prints "one", then "two"