Skip to content

Commit bdf950d

Browse files
committed
stream: allow returning null from pipeline tail
1 parent 45b5ca8 commit bdf950d

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
@@ -288,7 +288,9 @@ function pipelineImpl(streams, callback, opts) {
288288
then.call(ret,
289289
(val) => {
290290
value = val;
291-
pt.write(val);
291+
if (val != null) {
292+
pt.write(val);
293+
}
292294
if (end) {
293295
pt.end();
294296
}

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)