Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Last active December 12, 2017 14:34
Show Gist options
  • Save jooyunghan/13861bd6846374c3794e9ef2b9f4d73b to your computer and use it in GitHub Desktop.
Save jooyunghan/13861bd6846374c3794e9ef2b9f4d73b to your computer and use it in GitHub Desktop.
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