diff options
-rw-r--r-- | lib/internal/streams/pipeline.js | 3 | ||||
-rw-r--r-- | test/parallel/test-stream-pipeline.js | 18 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 95737d95e4..062bdc192d 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -138,10 +138,9 @@ async function pumpToNode(iterable, writable, finish, { end }) { if (end) { writable.end(); + await wait(); } - await wait(); - finish(); } catch (err) { finish(error !== err ? aggregateTwoErrors(error, err) : err); diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index d37ca275f1..e9f6a2fdf7 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -1616,3 +1616,21 @@ const tsp = require('timers/promises'); dup.push(null); dup.read(); } + +{ + let res = ''; + const writable = new Writable({ + write(chunk, enc, cb) { + res += chunk; + cb(); + } + }); + pipelinep(async function*() { + yield 'hello'; + await Promise.resolve(); + yield 'world'; + }, writable, { end: false }).then(common.mustCall(() => { + assert.strictEqual(res, 'helloworld'); + assert.strictEqual(writable.closed, false); + })); +} |