tc39 / proposal-async-iteration

Asynchronous iteration for JavaScript
https://tc39.github.io/proposal-async-iteration/
MIT License
859 stars 44 forks source link

yield* behavior on last iterator result #91

Closed GeorgNeis closed 7 years ago

GeorgNeis commented 7 years ago

yield* foo awaits on the value component of each result of foo, except for the last one (the one whose done component is true). I'm unsure if this is intended or a bug. If it is intended, I think it's worth having an explicit note about it in the spec.

@ajklein: FYI

domenic commented 7 years ago

I'm going to go with "intended". The protocol intentionally ignores any last values.

domenic commented 7 years ago

Oh, no, I forgot, the completion value of yield* is the last value. OK, so that's a bug.

arai-a commented 7 years ago

where does yield* await on "value" for not-last ones ?

GeorgNeis commented 7 years ago

Via GeneratorYield, yield* passes such a value to AsyncGeneratorResolve, which resolves a new promise with it:

Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « value »).

It then feeds this promise into the result promise from the queue:

Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], onFulfilled, undefined, promiseCapability).

In the case where value is itself a promise, this has the effect of yield* awaiting on it.

domenic commented 7 years ago

Basically the important thing is that value should not be a promise. It would be ideal if we didn't have two mechanisms for doing this, one in yield* and one in AsyncGeneratorResolve. But I am not sure how to accomplish that, and the version in #92 seems pretty straightforward.