Created
March 12, 2017 18:46
-
-
Save mightyguava/fe779d4a31bd0ddbbeb2d4bbb7b37c4c to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - Generator counts()
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* counts(start) { | |
yield start + 1; | |
yield start + 2; | |
yield start + 3; | |
return start + 4; | |
} | |
const counter = counts(0); | |
console.log(counter.next()); // {value: 1, done: false} | |
console.log(counter.next()); // {value: 2, done: false} | |
console.log(counter.next()); // {value: 3, done: false} | |
console.log(counter.next()); // {value: 4, done: true} | |
console.log(counter.next()); // {value: undefined, done: true} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment