Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/internal/streams/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
validateAbortSignal,
validateInteger,
validateObject,
validateBoolean,
} = require('internal/validators');
const { kWeakHandler } = require('internal/event_target');
const { finished } = require('internal/streams/end-of-stream');
Expand Down Expand Up @@ -397,13 +398,16 @@ function take(number, options = undefined) {
if (options?.signal != null) {
validateAbortSignal(options.signal, 'options.signal');
}
if (options?.destroyStream != null) {
validateBoolean(options.destroyStream, 'options.destroyStream');
}
Comment on lines +401 to +403
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another name would be better? Not sure what though... @benjamingr


number = toIntegerOrInfinity(number);
return async function* take() {
if (options?.signal?.aborted) {
throw new AbortError();
}
for await (const val of this) {
for await (const val of this.iterator({ destroyOnReturn: options?.destroyStream ?? true })) {
if (options?.signal?.aborted) {
throw new AbortError();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if the stream fails we should close the stream, WDYT @ronag ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcollina any thoughts on your side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after thinking I think it should be closed on an error as in the iterator helpers proposal spec the underlying iterator should be closed when it failed

Expand Down