Skip to content

Commit 56ec619

Browse files
committed
stream: return readable stream on promisified pipeline
1 parent c0a7020 commit 56ec619

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

lib/stream/promises.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ function pipeline(...streams) {
2323
signal = options.signal;
2424
}
2525

26-
pl(streams, (err, value) => {
26+
const stream = pl(streams, (err, value) => {
2727
if (err) {
2828
reject(err);
29-
} else {
29+
} else if (value !== undefined) {
3030
resolve(value);
31+
} else if (stream.readable) {
32+
resolve(stream);
33+
} else {
34+
resolve();
3135
}
3236
}, { signal });
3337
});

test/parallel/test-stream-pipeline.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,3 +1406,29 @@ const tsp = require('timers/promises');
14061406
}));
14071407
ac.abort();
14081408
}
1409+
1410+
{
1411+
const pipelinePromise = promisify(pipeline);
1412+
1413+
async function run() {
1414+
const read = new Readable({
1415+
read() {}
1416+
});
1417+
1418+
const duplex = new PassThrough();
1419+
1420+
read.push('data');
1421+
read.push(null);
1422+
1423+
const stream = await pipelinePromise(read, duplex);
1424+
1425+
let ret = ''
1426+
for await (const x of stream) {
1427+
ret += x;
1428+
}
1429+
1430+
assert.strictEqual(ret, 'data');
1431+
}
1432+
1433+
run();
1434+
}

0 commit comments

Comments
 (0)