Skip to content

Commit 088af2a

Browse files
committed
stream: return readable stream on promisified pipeline
1 parent e937662 commit 088af2a

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

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
@@ -1447,3 +1447,29 @@ const tsp = require('timers/promises');
14471447
assert.strictEqual(text, 'Hello World!');
14481448
}));
14491449
}
1450+
1451+
{
1452+
const pipelinePromise = promisify(pipeline);
1453+
1454+
async function run() {
1455+
const read = new Readable({
1456+
read() {}
1457+
});
1458+
1459+
const duplex = new PassThrough();
1460+
1461+
read.push('data');
1462+
read.push(null);
1463+
1464+
const stream = await pipelinePromise(read, duplex);
1465+
1466+
let ret = ''
1467+
for await (const x of stream) {
1468+
ret += x;
1469+
}
1470+
1471+
assert.strictEqual(ret, 'data');
1472+
}
1473+
1474+
run();
1475+
}

0 commit comments

Comments
 (0)