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

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎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+
consts=newPassThrough({objectMode: true});
1517+
pipeline(asyncfunction*(){
1518+
awaitPromise.resolve();
1519+
yield'hello';
1520+
yield'world';
1521+
yield'world';
1522+
},s,asyncfunction(source){
1523+
returnnull;
1524+
},common.mustCall((err,val)=>{
1525+
assert.strictEqual(err,undefined);
1526+
assert.strictEqual(val,null);
1527+
}));
1528+
}

0 commit comments

Comments
 (0)