From 1b47866a1d94224678ce05e7c7355ff17ad9cce6 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 25 Feb 2022 14:31:20 +0100 Subject: [PATCH] stream: allow returning null from pipeline tail PR-URL: https://github.com/nodejs/node/pull/42078 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum --- lib/internal/streams/pipeline.js | 4 +++- test/parallel/test-stream-pipeline.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 36e1aebdd10e10..a3f69c2099ace1 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -288,7 +288,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(); } diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index 1948eeef8af257..eecf836b5bb77f 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -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); + })); +}