From bdf950d5cc55be893181f28b842b91d6fe0a3309 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 | 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); + })); +}