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: return readable stream on promisified pipeline #40653

Closed
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/stream/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ function pipeline(...streams) {
signal = options.signal;
}

pl(streams, (err, value) => {
const stream = pl(streams, (err, value) => {
if (err) {
reject(err);
} else {
} else if (value !== undefined) {
resolve(value);
} else if (stream.readable) {
resolve(stream);
ronag marked this conversation as resolved.
Show resolved Hide resolved
} else {
resolve();
}
}, { signal });
});
Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1447,3 +1447,29 @@ const tsp = require('timers/promises');
assert.strictEqual(text, 'Hello World!');
}));
}

{
const pipelinePromise = promisify(pipeline);

async function run() {
const read = new Readable({
read() {}
});

const duplex = new PassThrough();

read.push('data');
read.push(null);

const stream = await pipelinePromise(read, duplex);

let ret = ''
ronag marked this conversation as resolved.
Show resolved Hide resolved
for await (const x of stream) {
ret += x;
}

assert.strictEqual(ret, 'data');
}

run();
}