@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
51 lines (50 loc) • 1.78 kB
text/typescript
import { ForkableStream } from '@johngw/stream/sinks/ForkableStream';
import { ControllableReadableStream } from '@johngw/stream/sources/Controllable';
import { Subjectable } from '@johngw/stream/subjects/Subjectable';
/**
* A Subject is a combination of a {@link ControllableStream:class}
* and a {@link ForkableStream:class} giving the developer the
* ability to both queue items and fork the stream from the same object.
*
* @group Subjects
* @example
* ```
* const subject = new Subject<number>()
*
* subject.enqueue(1)
* subject.enqueue(2)
* subject.enqueue(3)
*
* subject.fork().pipeTo(write(chunk => console.info(chunk)))
* ```
*/
export interface SubjectOptions<In, Out = In> {
controllable?: ControllableReadableStream<In>;
forkable?: ForkableStream<Out>;
pipeThroughOptions?: StreamPipeOptions;
pipeToOptions?: StreamPipeOptions;
pre?: TransformStream<In, In>[];
post?: TransformStream<Out, Out>[];
transform?: TransformStream<In, Out>;
}
/**
* The base class for all subjects.
*
* @group Subjects
* @see {@link Subject:class}
* @see {@link StatefulSubject:class}
*/
export declare class Subject<In, Out = In> implements Subjectable<In, Out> {
#private;
constructor({ controllable, forkable, pre, post, transform, pipeThroughOptions, pipeToOptions, }?: SubjectOptions<In, Out>);
protected get controllable(): ControllableReadableStream<In>;
get finished(): boolean;
protected get forkable(): ForkableStream<Out>;
fork(): ReadableStream<Out>;
write(queuingStrategy?: QueuingStrategy<In>): WritableStream<In>;
/**
* Returns a proxy to the ControllableStream. Once all proxies
* have been closed, then the source is also closed.
*/
control(): ControllableReadableStream<In>;
}