Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function asyncTask(count, gen) {
setTimeout(() => {
gen.next(count);
}, 1000);
}
const generator = (function* () {
let count = 0;
console.log(yield asyncTask(count++, generator));
console.log(yield asyncTask(count++, generator));
console.log("complete");
})();
generator.next();
/*
0
1
complete
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment