Closed
Description
Given the following code, any promises for iterator results after the stream has ended will never resolve.
const a = new stream.PassThrough()
const b = a[Symbol.asyncIterator]()
const c = b.next()
const d = b.next()
a.end()
await c // { done: true, value: null }
await d // never resolves
if you repeat the same process for a generator function
const a = (async function* (){})()
const b = a[Symbol.asyncIterator]()
const c = b.next()
const d = b.next()
a.end()
await c // { value: undefined, done: true }
await d // { value: undefined, done: true }
Any promises from calls to next from an exhausted async generator function's iterator will immediately resolve as done: true
.
I noticed this difference when trying to perform parallel async transforms on the values from a stream that resolved in a non deterministic order. I rely on all calls to next after the source has been exhausted to resolve, and since they don't for streams it hung forever.
I'm unsure of if this is defined in the async iterator spec, but it does seem like it might want to match behaviors of async generator functions.
Metadata
Metadata
Assignees
Labels
No labels