Skip to content

Commit 6739db8

Browse files
committed
chore(node): add Readable.from utility
Added in v12.3.0 from PR nodejs/node#27660
1 parent e94ce02 commit 6739db8

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

types/node/stream.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ declare module "stream" {
1818
}
1919

2020
class Readable extends Stream implements NodeJS.ReadableStream {
21+
static from(iterable: Iterable<any> | AsyncIterable<any>, opts?: ReadableOptions): NodeJS.ReadableStream;
2122
readable: boolean;
2223
readonly readableHighWaterMark: number;
2324
readonly readableLength: number;

types/node/test/stream.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,17 @@ function stream_readable_pipe_test() {
192192
z.close();
193193
rs.close();
194194
}
195+
196+
async function readable_from() {
197+
const list = [ 1, 2, 3 ];
198+
const listPromise = list.map(n => Promise.resolve(n)));
199+
200+
const readableSync = Readable.from(list);
201+
const readableAsync = Readable.from(listPromise);
202+
203+
let i = 0;
204+
readableSync.on('data', n => assert(n === list[i++]));
205+
206+
let j = 0;
207+
readableAsync.on('data', n => assert(n === list[j++]));
208+
}

0 commit comments

Comments
 (0)