Created
September 11, 2017 08:05
-
-
Save sue71/e7865f002d3cd8c0d798fb8d710d1232 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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