Skip to content

Instantly share code, notes, and snippets.

@aeruhxi
Created September 12, 2016 18:52
Show Gist options
  • Save aeruhxi/ff4e9e6d58fa3f28ed6ec350d1d45a0a to your computer and use it in GitHub Desktop.
Save aeruhxi/ff4e9e6d58fa3f28ed6ec350d1d45a0a to your computer and use it in GitHub Desktop.
generator wrapper
function runGenerator(g) {
var it = g(), ret;
(function iterate(val){
ret = it.next( val );
if (!ret.done) {
if ("then" in ret.value) {
ret.value.then( iterate );
}
else {
setTimeout( function(){
iterate( ret.value );
}, 0 );
}
}
})();
}
runGenerator(function *() {
// do async stuff
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment