From 896ae0e7a7562bfd6cb10d60db89bd8b67cdf0b7 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 22 Feb 2022 15:31:41 +0100 Subject: [PATCH] stream: allow returning null from pipeline tail --- lib/internal/streams/pipeline.js | 4 +++- test/parallel/test-stream-pipeline.js | 16 ++++++++++++++++ 2 files changed, 19 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..a5d92fa334e3ff 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -1511,3 +1511,19 @@ 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); + })); +}