Skip to content

Instantly share code, notes, and snippets.

@tanner-west
Last active February 10, 2022 21:58
Show Gist options
  • Save tanner-west/7e0f0d5ac1f2080e896215d6a2e4186e to your computer and use it in GitHub Desktop.
Save tanner-west/7e0f0d5ac1f2080e896215d6a2e4186e to your computer and use it in GitHub Desktop.
function getTwoPlusTwo() {
return 2 + 2
}
function* myGeneratorFunction() {
const sum = yield getTwoPlusTwo()
console.log("two plus two equals: ", sum)
}
const g = myGeneratorFunction();
console.log("calling next the first time...")
console.log("next: ", g.next())
console.log("calling next the second time...")
console.log("next: ", g.next())
// calling next the first time...
// next: { value: 4, done: false }
// calling next the second time...
// two plus two equals: undefined
// next: { value: undefined, done: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment