Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/stream/promises.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const {
ArrayIsArray,
ArrayPrototypePop,
Promise,
} = primordials;
Expand Down Expand Up @@ -28,13 +29,22 @@ function pipeline(...streams) {
end = options.end;
}

pl(streams, (err, value) => {
let lastStream = streams[streams.length - 1];
if (streams.length === 1 && ArrayIsArray(streams[0])) {
lastStream = streams[0][streams[0].length - 1];
}

const stream = pl(streams, (err, value) => {
if (err) {
reject(err);
} else {
resolve(value);
}
}, { signal, end });

if (typeof lastStream === 'function' && stream.readable) {
stream.resume();
}
});
}

Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,22 @@ tmpdir.refresh();
}));
}

{
async function* passThrough(source) {
for await (const chunk of source) {
yield chunk;
}
}

const streams = () => [
Readable.from(Array.from({ length: 100 }, (_, i) => i)),
passThrough,
];

pipelinep(...streams()).then(common.mustCall());
pipelinep(streams()).then(common.mustCall());
}

{
const r = new Readable();
for (let i = 0; i < 4000; i++) {
Expand Down
Loading