Created
September 11, 2017 08:04
-
-
Save sue71/7b0883eb7e8cf28f8aa5e8a0bb1e472b 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, 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