Skip to content

Instantly share code, notes, and snippets.

@ostronom
Created June 1, 2012 13:07
Show Gist options
  • Select an option

  • Save ostronom/2852023 to your computer and use it in GitHub Desktop.

Select an option

Save ostronom/2852023 to your computer and use it in GitHub Desktop.
madness
# async calls sequentalization
apply = (f, s) -> () -> f( () -> s() )
id = (args...) -> args
foldr = (f, z, [x, xs...]) -> if x then f x, (foldr f, z, xs) else z
chain = (funcs...) -> (foldr apply, id, funcs)()
action1 = (done) ->
async_action_with_callback(done)
action2 = (done) ->
async_action_with_callback(done)
# ...
actionN = (done) ->
async_action_with_callback(done)
chain action1, action2, ..., actionN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment