Skip to content

Commit

Permalink
chore(node): add Readable.from utility
Browse files Browse the repository at this point in the history
Added in v12.3.0 from PR nodejs/node#27660
  • Loading branch information
imcotton committed Jun 11, 2019
1 parent e94ce02 commit 0a295fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions types/node/stream.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference lib="es2018.asynciterable" />

declare module "stream" {
import * as events from "events";

Expand All @@ -18,6 +20,7 @@ declare module "stream" {
}

class Readable extends Stream implements NodeJS.ReadableStream {
static from(iterable: Iterable<any> | AsyncIterable<any>, opts?: ReadableOptions): NodeJS.ReadableStream;
readable: boolean;
readonly readableHighWaterMark: number;
readonly readableLength: number;
Expand Down
14 changes: 14 additions & 0 deletions types/node/test/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,17 @@ function stream_readable_pipe_test() {
z.close();
rs.close();
}

async function readable_from() {
const list = [ 1, 2, 3 ];
const listPromise = list.map(n => Promise.resolve(n)));

const readableSync = Readable.from(list);
const readableAsync = Readable.from(listPromise);

let i = 0;
readableSync.on('data', n => assert(n === list[i++]));

let j = 0;
readableAsync.on('data', n => assert(n === list[j++]));
}

0 comments on commit 0a295fc

Please sign in to comment.