UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

42 lines 1.18 kB
import type { Controllable, ControllerPullListener } from './Controllable.js'; /** * A ControllableStream is ReadableStream that can have chunks * queued to from an external source. * * @group Sources * @example * Queuing items externally. * * ``` * const controller = new ControllableStream<number>() * controller.enqueue(1) * controller.enqueue(2) * controller.enqueue(3) * controller.close() * ``` * * Registering pull subscribers externally. * * ``` * const controller = new ControllableStream<number>() * let i = -1 * controller.onPull(() => ++i) * ``` */ export declare class ControllableStream<T> extends ReadableStream<T> implements Controllable<T> { #private; constructor(strategy?: QueuingStrategy<T>); get desiredSize(): number | null; /** * Register a pull subscriber. * * @remark * When the stream is ready to pull it will pull from all * subscribers until the desired size has been fulfilled. */ onPull(pullListener: ControllerPullListener<T>): () => void; error(error?: unknown): void; enqueue(chunk: T): void; close(): void; } //# sourceMappingURL=ControllableStream.d.ts.map