Skip to content

Instantly share code, notes, and snippets.

@sue71
Created September 11, 2017 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sue71/e7865f002d3cd8c0d798fb8d710d1232 to your computer and use it in GitHub Desktop.
Save sue71/e7865f002d3cd8c0d798fb8d710d1232 to your computer and use it in GitHub Desktop.
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