1function* g1() {
2 yield 2;
3 yield 3;
4 yield 4;
5}
6
7function* g2() {
8 yield 1;
9 yield* g1();
10 yield 5;
11}
12
13const iterator = g2();
14
15console.log(iterator.next()); // {value: 1, done: false}
16console.log(iterator.next()); // {value: 2, done: false}
17console.log(iterator.next()); // {value: 3, done: false}
18console.log(iterator.next()); // {value: 4, done: false}
19console.log(iterator.next()); // {value: 5, done: false}
20console.log(iterator.next()); // {value: undefined, done: true}
21
1function* foo(index) {
2 while (index < 2) {
3 yield index;
4 index++;
5 }
6}
7
8const iterator = foo(0);
9
10console.log(iterator.next().value);
11// expected output: 0
12
13console.log(iterator.next().value);
14// expected output: 1