@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
62 lines • 2.21 kB
TypeScript
import { ForkableStream } from '../sinks/ForkableStream.js';
import type { ControllableReadableStream } from '../sources/Controllable.js';
import type { Subjectable } from './Subjectable.js';
import type { StreamPipeOptions, UnderlyingDefaultSource } from 'node:stream/web';
/**
* 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 type SubjectOptions<In, Out> = SubjectOptionsBase<In, Out> & SubjectControllableOptions<In> & SubjectForkableOptions<Out>;
interface SubjectOptionsBase<In, Out = In> {
pipeThroughOptions?: StreamPipeOptions;
pipeToOptions?: StreamPipeOptions;
pre?: TransformStream<In, In>[];
post?: TransformStream<Out, Out>[];
transform?: TransformStream<In, Out>;
}
type SubjectControllableOptions<In> = {
controllable?: ControllableReadableStream<In>;
} | {
controllableStrategy?: QueuingStrategy<In>;
};
type SubjectForkableOptions<Out> = {
forkable?: ForkableStream<Out>;
} | {
forkableStrategy?: QueuingStrategy<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(options?: SubjectOptions<In, Out>);
protected get controllable(): ControllableReadableStream<In>;
get finished(): boolean;
protected get forkable(): ForkableStream<Out>;
fork(underlyingSource?: UnderlyingDefaultSource<Out>, queuingStrategy?: QueuingStrategy<Out>): 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>;
}
export {};
//# sourceMappingURL=Subject.d.ts.map