Created
March 12, 2017 18:47
-
-
Save mightyguava/051a3cd5535462751ae2ee2faac5c36c to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - Generator printer()
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* printer() { | |
console.log("We are starting!"); | |
console.log(yield); | |
console.log(yield); | |
console.log(yield); | |
console.log("We are done!"); | |
} | |
const counter = printer(); | |
counter.next(1); // We are starting! | |
counter.next(2); // 2 | |
counter.next(3); // 3 | |
counter.next(4); // 4\n We are done! | |
counter.next(5); // <doesn't print anything> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment