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 updateit_pauses=->loopdo somethingEveryFrame
pause!# continue in next frameit_waits=->loopfor thing in things
dothing.action
wait!100# continue after 100 millisecondsit_flows=-># a coro that can optionally be waited on by anotherone= (nxt) ->
wait!1000console.log'one'
nxt?()
two=->
one!# wait for one to finishconsole.log'two'do two # after a second, prints "one", then "two"