Skip to content

Instantly share code, notes, and snippets.

@mu-hun
Created September 30, 2020 05:07
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 mu-hun/7c8af16ff33699ab4b1583ab95161710 to your computer and use it in GitHub Desktop.
Save mu-hun/7c8af16ff33699ab4b1583ab95161710 to your computer and use it in GitHub Desktop.
YDKJS generator example
let z = 1;
function *foo() {
const x = yield 2;
z++
const y = yield (x*z)
console.log(x, y, z)
}
const it_first = foo()
const it_second = foo()
let first_value = it_first.next().value;
console.log(first_value)
let second_value = it_second.next().value
console.log(second_value)
first_value = it_first.next(second_value * 10)
// const x = yield
// .value = x*z
.value;
console.log(first_value)
second_value = it_second.next(first_value * 5).value
console.log(second_value)
it_first.next(second_value / 2)
it_second.next(first_value / 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment