Skip to content

Instantly share code, notes, and snippets.

@homam
Created December 7, 2014 21:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homam/5dfa9fd66d7698280c30 to your computer and use it in GitHub Desktop.
Save homam/5dfa9fd66d7698280c30 to your computer and use it in GitHub Desktop.
spawn lazy primises
next-i = do ->
j = 1
(i) ->
success, reject <- new Promise _
success i + j
spawn = (gen) ->
success, reject <- new Promise _
next = (last) ->
{value, done} = gen.next last
return value.then next, reject if not done
success value
next!
# next-i 2 .then -> console.log it
do-some-work = ->*
s1 = yield next-i 10
s2 = yield next-i s1
return s1 + s2
spawn do-some-work! .then ->
console.log "***", it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment