Skip to content

Instantly share code, notes, and snippets.

@amoilanen
Created January 6, 2016 16:13
Show Gist options
  • Save amoilanen/db9c962d11306f64631c to your computer and use it in GitHub Desktop.
Save amoilanen/db9c962d11306f64631c to your computer and use it in GitHub Desktop.
Yielding generator from a generator: seemless to the client code
function* func1() {
var y = yield 'b';
console.log('y = ', y);
return 'c';
}
function* func() {
var x = yield 'a'
console.log("x = ", x);
var z = yield* func1();
console.log("z = ", z);
return 'd';
}
var i = 0;
var it = func();
var next = it.next();
while (!next.done) {
console.log(next);
next = it.next(i++);
}
//Object { value="a", done=false}
//x = 0
//Object { value="b", done=false}
//y = 1
//z = c
//Object { value="d", done=true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment