proposal-async-iterator-helpers
proposal-async-iterator-helpers copied to clipboard
should `AsyncIterator.zip` await values yielded from sync iterators?
AsyncIterator.zip([asyncIterator, syncIterable])
should presumably work (once we get Iterator.zip
).
for await (let val of [Promise.resolve(0)])
will await the promise, binding 0
to val
. I think necessarily that means that AsyncIterator.from([Promise.resolve(0)])
must as well, such that AsyncIterator.from([Promise.resolve(0)]).forEach(console.log)
will print 0
. This preserves the invariant that async iterables never yield promises.
But for zip
, we don't necessarily have to match that behavior, because the results are boxed, not yielded directly, so the invariant is upheld either way. Question, then: should zip
await
values yielded by sync iterators?
On the one hand, "it promotes to async iterator, and then zips that" is the obvious intuition, which suggests that it should await
.
On the other hand, that behavior is very easy to recover if it does not await
values from the zipped things (simply do the AsyncIterator.from
yourself), whereas recovering the "not await" behavior is pretty annoying if it does await
them.
Thoughts? @michaelficarra expressed a preference for not await
ing.