UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

65 lines (64 loc) 1.52 kB
/** * Creates a readable stream from an collection of values. * * @group Sources * @example * Using an iterable * ``` * fromCollection([1, 2, 3, 4]) * ``` * * Using an Async Iterable * ``` * fromCollection((async function* () { * yield 1 * })()) * ``` * * Using an ArrayLike * ``` * fromCollection({ * 0: 'zero', * 1: 'one', * 2: 'two', * length: 3, * }) * ``` */ export declare function fromCollection<T>(collection: Iterator<T> | Iterable<T> | AsyncIterator<T> | AsyncIterable<T> | ArrayLike<T>, queuingStrategy?: QueuingStrategy<T>): ReadableStream<T>; /** * An underlying source for an `Iterator` or `AsyncIterator`. * * @group Sources * @example * ``` * const reader = new ReadableStream(new IteratorSource((function* () { * yield 1 * yield 2 * })())) * ``` */ export declare class IteratorSource<T> implements UnderlyingDefaultSource<T> { #private; constructor(iterator: Iterator<T> | AsyncIterator<T>); pull(controller: ReadableStreamDefaultController<T>): Promise<void>; } /** * An underlying source for an `ArrayLike`. * * @group Sources * @example * ``` * const reader = new ReadableStream(new ArrayLikeSource({ * 0: 'zero', * 1: 'one', * length: 2 * })) * ``` */ export declare class ArrayLikeSource<T> implements UnderlyingDefaultSource<T> { #private; constructor(arrayLike: ArrayLike<T>); start(controller: ReadableStreamDefaultController<T>): void; pull(controller: ReadableStreamDefaultController<T>): void; }