QUOTE:
The yield*
operator delegates to another generator. This provides a convenient mechanism for composing generators.
The expression yield* <<expr>>
is equivalent to:
let (g = <<expr>>) {
let received = void 0, send = true, result = void 0;
try {
while (true) {
let next = send ? g.send(received) : g.throw(received);
try {
received = yield next;
send = true;
} catch (e) {
received = e;
send = false;
}
}
} catch (e) {
if (!isStopIteration(e))
throw e;
result = e.value;
} finally {
try { g.close(); } catch (ignored) { }
}
result
}
This is similar to a for-in
loop over the generator, except that it propagates exceptions thrown via the outer generator’s throw
method into the delegated generator.
Source: http://wiki.ecmascript.org/doku.php?id=harmony:generators#delegating_yield
I haven't taken much time to fully understand it, but yield* gen;
seems similar to yield gen();
Correct me if I'm wrong (though I fully suspect there will be some corner cases, such as the context of any exceptions.)