Skip to content

Instantly share code, notes, and snippets.

@mightyguava
Created March 12, 2017 18:47
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 mightyguava/051a3cd5535462751ae2ee2faac5c36c to your computer and use it in GitHub Desktop.
Save mightyguava/051a3cd5535462751ae2ee2faac5c36c to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - Generator printer()
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