Create a gist now

Instantly share code, notes, and snippets.

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