Skip to content

Commit 53338fe

Browse files
ronagsxa
authored andcommitted
stream: allow returning null from pipeline tail
PR-URL: #42078 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent a32ec98 commit 53338fe

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/internal/streams/pipeline.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ function pipelineImpl(streams, callback, opts) {
265265
then.call(ret,
266266
(val) => {
267267
value = val;
268-
pt.write(val);
268+
if (val != null) {
269+
pt.write(val);
270+
}
269271
if (end) {
270272
pt.end();
271273
}

test/parallel/test-stream-pipeline.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,3 +1511,18 @@ const tsp = require('timers/promises');
15111511
assert.strictEqual(s.destroyed, true);
15121512
}));
15131513
}
1514+
1515+
{
1516+
const s = new PassThrough({ objectMode: true });
1517+
pipeline(async function*() {
1518+
await Promise.resolve();
1519+
yield 'hello';
1520+
yield 'world';
1521+
yield 'world';
1522+
}, s, async function(source) {
1523+
return null;
1524+
}, common.mustCall((err, val) => {
1525+
assert.strictEqual(err, undefined);
1526+
assert.strictEqual(val, null);
1527+
}));
1528+
}

0 commit comments

Comments
 (0)