Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions lib/internal/streams/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
validateFunction,
} = require('internal/validators');
const { kWeakHandler, kResistStopPropagation } = require('internal/event_target');
const destroyImpl = require('internal/streams/destroy');
const { finished } = require('internal/streams/end-of-stream');

const kEmpty = Symbol('kEmpty');
Expand Down Expand Up @@ -177,6 +178,7 @@ function map(fn, options) {
resume();
resume = null;
}
destroyImpl.destroyer(stream, null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is an abrupt destroy the right thing here? Or should it be a natural close? @ronag @mcollina ... I'm legitimately not sure which is most correct here.

}
}.call(this);
}
Expand Down
32 changes: 31 additions & 1 deletion test/parallel/test-stream-some-find-every.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as common from '../common/index.mjs';
import { setTimeout } from 'timers/promises';
import { Readable } from 'stream';
import { PassThrough, Readable } from 'stream';
import assert from 'assert';


Expand Down Expand Up @@ -77,6 +77,36 @@ function oneTo5Async() {
await findStream.find(common.mustCall((x) => x > 1, 2));
await checkDestroyed(findStream);

const openSomeStream = new PassThrough({ objectMode: true });
openSomeStream.write(1);
openSomeStream.write(2);
openSomeStream.write(3);
assert.strictEqual(
await openSomeStream.some(common.mustCall((x) => x > 2, 3)),
true,
);
await checkDestroyed(openSomeStream);

const openEveryStream = new PassThrough({ objectMode: true });
openEveryStream.write(1);
openEveryStream.write(2);
openEveryStream.write(3);
assert.strictEqual(
await openEveryStream.every(common.mustCall((x) => x < 3, 3)),
false,
);
await checkDestroyed(openEveryStream);

const openFindStream = new PassThrough({ objectMode: true });
openFindStream.write(1);
openFindStream.write(2);
openFindStream.write(3);
assert.strictEqual(
await openFindStream.find(common.mustCall((x) => x > 1, 2)),
2,
);
await checkDestroyed(openFindStream);

// When short circuit isn't possible the whole stream is iterated
await oneTo5().some(common.mustCall(() => false, 5));
await oneTo5().every(common.mustCall(() => true, 5));
Expand Down
Loading