From 53338fe65cd6f992462091bd0ace22a7ec019f42 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 623973ff316453..5fb11f1632fdca 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -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(); } diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index 81f350df0d68fd..bd676d9fe7e701 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); + })); +}