You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add non-destroying AsyncIterator to Readable streams #38491
Is your feature request related to a problem? Please describe.
The current async-iterator on Readable streams always destroys the stream, when you break or return or an error is thrown. Specifically, this means that if someone wants to iterate over the same stream in different places (for example iterate until the end of part one... then do some things, continue iterating later etc) this is impossible - you have to have exactly one for await...of that you work inside of. In addition, there are other scenarios like Request where iterating over the request ends up closing the response (which might specifically be a bug in the Request iterator, and not really related to destroying the request) and this suggestion would allow bypassing it for other use-cases without adding special specific use-case code (I'm not sure if this is an issue with Duplex streams in general?).
Describe the solution you'd like
I'd like to create another async-iterator (in addition to the existing one) that would give users the option opt in/out of destroying the stream non-error ending of the iteration (any maybe also on stream-error?). The naming could be very explicit, to let users know that they've decided to opt-out of the default behavior, or if an explicit name is not required just added as parameters to the Symbol.asyncIterator method.
Something like this (I haven't thought a lot about the naming):
Definitely 👍 to this, I've also been in situations where I've piped a stream to a dummy PassThrough just so I could iterate over it without destroying the original stream.
Activity
addaleax commentedon May 1, 2021
Definitely 👍 to this, I've also been in situations where I've piped a stream to a dummy
PassThroughjust so I could iterate over it without destroying the original stream.misos1 commentedon May 2, 2021
Actually
Requestis not destroyed whenfor awaitdoes not break or throw (but for example file stream is) if you meant that:ronag commentedon May 2, 2021
ronag commentedon May 3, 2021
Because it's a generic method
stream: add a non-destroying iterator to Readable
stream: add a non-destroying iterator to Readable
stream: add a non-destroying iterator to Readable