Skip to content

Commit

Permalink
stream: allow returning null from pipeline tail
Browse files Browse the repository at this point in the history
PR-URL: #42078
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
ronag authored and sxa committed Mar 7, 2022
1 parent a32ec98 commit 53338fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ function pipelineImpl(streams, callback, opts) {
then.call(ret,
(val) => {
value = val;
pt.write(val);
if (val != null) {
pt.write(val);
}
if (end) {
pt.end();
}
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1511,3 +1511,18 @@ const tsp = require('timers/promises');
assert.strictEqual(s.destroyed, true);
}));
}

{
const s = new PassThrough({ objectMode: true });
pipeline(async function*() {
await Promise.resolve();
yield 'hello';
yield 'world';
yield 'world';
}, s, async function(source) {
return null;
}, common.mustCall((err, val) => {
assert.strictEqual(err, undefined);
assert.strictEqual(val, null);
}));
}

0 comments on commit 53338fe

Please sign in to comment.