Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: support array of streams in promises pipeline #40193

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions lib/internal/streams/pipeline.js
Expand Up @@ -166,17 +166,14 @@ async function pump(iterable, writable, finish) {
}

function pipeline(...streams) {
const callback = once(popCallback(streams));
return pipelineImpl(streams, once(popCallback(streams)));
}

// stream.pipeline(streams, callback)
if (ArrayIsArray(streams[0]) && streams.length === 1) {
function pipelineImpl(streams, callback, opts) {
if (streams.length === 1 && ArrayIsArray(streams[0])) {
streams = streams[0];
}

return pipelineImpl(streams, callback);
}

function pipelineImpl(streams, callback, opts) {
if (streams.length < 2) {
throw new ERR_MISSING_ARGS('streams');
}
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-stream-pipeline.js
Expand Up @@ -1406,3 +1406,44 @@ const tsp = require('timers/promises');
}));
ac.abort();
}

{
async function run() {
let finished = false;
let text = '';
const write = new Writable({
write(data, enc, cb) {
text += data;
cb();
}
});
write.on('finish', () => {
finished = true;
});

await pipelinep([Readable.from('Hello World!'), write]);
assert(finished);
assert.strictEqual(text, 'Hello World!');
}

run();
lpinca marked this conversation as resolved.
Show resolved Hide resolved
}

{
let finished = false;
let text = '';
const write = new Writable({
write(data, enc, cb) {
text += data;
cb();
}
});
write.on('finish', () => {
finished = true;
});

pipeline([Readable.from('Hello World!'), write], common.mustSucceed(() => {
assert(finished);
assert.strictEqual(text, 'Hello World!');
}));
}