Skip to content

Commit 745f393

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

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,26 @@ function stream_readable_pipe_test() {
192192
z.close();
193193
rs.close();
194194
}
195+
196+
async function readable_from() {
197+
198+
const list = [ 1, 2, 3 ];
199+
const listPromise = list.map(async n => await n);
200+
201+
const readableSync = Readable.from(list);
202+
const readableAsync = Readable.from(listPromise);
203+
204+
let i = 0;
205+
206+
for await (const n of readableSync) {
207+
assert(n === list[i++]);
208+
}
209+
210+
i = 0;
211+
212+
for await (const n of readableAsync) {
213+
assert(n === list[i++]);
214+
}
215+
216+
}
217+

0 commit comments

Comments
 (0)