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
stream: Add option to Readable.take operator to not close the stream #46980
constcsvParsedStream=fs.createReadStream('file.csv').compose(csvParse({columns: false}));const[columns]=awaitcsvParsedStream.take(1).toArray();// This will now be empty and no data as take already consumed the streamconstparsed=awaitcsvParsedStream.map((row)=>parseRowByColumns(row,columns)).toArray();
Another example (I know I can use [first, ...rest] this is just an example):
What is the feature you are proposing to solve the problem?
Adding closeStream option to the take operator that with default value true that I could disable closing the stream
constcsvParsedStream=fs.createReadStream('file.csv').compose(csvParse({columns: false}));const[columns]=awaitcsvParsedStream.take(1,{closeStream: false})// Right now this would close the stream, but we give it an option to not.toArray();constparsed=awaitcsvParsedStream.map((row)=>parseRowByColumns(row,columns)).toArray();
What alternatives have you considered?
Get the first value from stream as async itarator and rest
Basically, RxJs pipes don't change the original producer and most of the time don't wait for subscribers to start emitting, and no backpressure from what I know...
I still think we don't fundamentally understand this well enough. Our iterator helpers are on the iterator (like the tc39 proposal) and not on the iterables so it's hard to come up with good analogies regarding whether or not .take should destroy the stream or not.
On one hand the proposal spec clearly states the underlying iterator should be closedd. On the other hand in models based on iterables and not iterators this wouldn't have been a problem.
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-staleIssues and PRs exempt from automated stale handling.
label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
Activity
rluvaton commentedon Mar 6, 2023
I'll implement this if we think it's a good addition.
Cc. @benjamingr @mcollina @ronag
benjamingr commentedon Mar 7, 2023
What does a .NET IEnumerable do for example?
rluvaton commentedon Mar 7, 2023
Takemultiple times just returns the same data:benjamingr commentedon Mar 7, 2023
@Linkgoron @ronag wdyt?
ronag commentedon Mar 7, 2023
I think Ienumerable is not relevant. It's Observable operators (async) we should look at.
rluvaton commentedon Mar 7, 2023
Same in rxjs:
rluvaton commentedon Mar 7, 2023
Although if you do this:
It logs 0, 1
Basically, RxJs pipes don't change the original producer and most of the time don't wait for subscribers to start emitting, and no backpressure from what I know...
benjamingr commentedon Mar 7, 2023
The issue is that in Rx you compose the observable (operation) and not the observer.
In node the operators are on the iterator and not the iterable.
rluvaton commentedon Mar 8, 2023
Any bottom line? @ronag WDYT?
stream: allow stream to stay open after take
rluvaton commentedon Mar 9, 2023
This is how I think it should be implemented, any thoughts?:
benjamingr commentedon Mar 9, 2023
I still think we don't fundamentally understand this well enough. Our iterator helpers are on the iterator (like the tc39 proposal) and not on the iterables so it's hard to come up with good analogies regarding whether or not
.takeshould destroy the stream or not.On one hand the proposal spec clearly states the underlying iterator should be closedd. On the other hand in models based on iterables and not iterators this wouldn't have been a problem.
We should bring this up with TC39 too.
rluvaton commentedon Mar 9, 2023
this is why by default it will close, having an option to not close is a problem?
32 remaining items
github-actions commentedon Nov 29, 2025
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-staleIssues and PRs exempt from automated stale handling.
label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
dmurvihill commentedon Nov 30, 2025
please leave open
github-actions commentedon Jun 28, 2026
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
dmurvihill commentedon Jun 28, 2026
Leave open please
github-actions commentedon Sep 28, 2026
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
dmurvihill commentedon Sep 29, 2026
Leave open please