Created
December 7, 2014 21:44
-
-
Save homam/5dfa9fd66d7698280c30 to your computer and use it in GitHub Desktop.
spawn lazy primises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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