Guest User

Untitled

a guest
Oct 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. # async calls sequentalization
  2.  
  3. apply = (f, s) -> () -> f( () -> s() )
  4. id = (args...) -> args
  5. foldr = (f, z, [x, xs...]) -> if x then f x, (foldr f, z, xs) else z
  6. chain = (funcs...) -> (foldr apply, id, funcs)()
  7.  
  8. action1 = (done) ->
  9. async_action_with_callback(done)
  10.  
  11. action2 = (done) ->
  12. async_action_with_callback(done)
  13.  
  14. # ...
  15.  
  16. actionN = (done) ->
  17. async_action_with_callback(done)
  18.  
  19. chain action1, action2, ..., actionN
Add Comment
Please, Sign In to add comment