Last active
December 12, 2017 14:34
-
-
Save jooyunghan/13861bd6846374c3794e9ef2b9f4d73b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function coro(g) { | |
let gId = 0; | |
wireTimeout(g.next(), gId); | |
function resume(value) { | |
wireTimeout(g.next(value), ++gId); | |
}; | |
function wireTimeout(result, id) { | |
if (result && result.value instanceof Promise) { | |
result.value.then(v => { if (id === gId) resume(v) }); | |
} | |
} | |
return resume; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment