Classes

Interfaces

I
Channel

The producer half of StreamClass.channel: emit into it, consume stream out of it.

  • abort(reason: unknown): void

    Rejects the consuming Task with reason — the two-tier rule's bug tier. Idempotent.

  • buffered: number

    Elements buffered for a consumer that has not taken them yet.

  • close(): void

    Ends the stream once the buffer drains. Idempotent.

  • closed: boolean

    Whether the channel has been closed, aborted, or abandoned by its consumer.

  • dropped: number

    How many elements the buffer has lost to overflow. 0 unless a consumer fell behind.

  • emit(value: T): boolean

    Offers a value. Returns false when there is no room left — Node's write() convention: advisory for a producer that can slow down, ignorable for one that cannot.

  • fail(error: E): boolean

    Offers a declared failure as an element — the railway, not a rejection.

  • ready(): Promise<void>

    Resolves once there is room to emit again — Web Streams' writer.ready, and the promise form of Node's 'drain'.

  • stream: Stream<T, E>

    The consuming half. One consumer only; a second pass throws.

I
ChannelOptions

How a Channel behaves when its consumer cannot keep up.

  • capacity: number

    How many elements to buffer for a consumer that has not taken them yet. Default 10_000.

  • onDemand: () => void

    Called once, when a consumer first attaches. A producer that can defer starting should start here: it is the difference between a buffer that stays near empty and one that races ahead of a consumer that has not arrived.

  • onDiscard: (
    dropped: T | E,
    buffered: number
    ) => void

    Called with each element the buffer actually lost, and the depth after the loss. The only place overflow is observable — make it fatal from here by calling fail or abort.

  • overflow: Overflow

    What to do once capacity is reached: drop from either end, or 'fail' — end the stream with a ChannelOverflowFailure element instead of losing anything quietly. Default 'dropOldest'.

Type Aliases

T
ChannelOverflowFailure = Of<ChannelOverflow>

The failure element a 'fail' channel ends with.

T
Overflow = "dropOldest" | "dropNewest" | "fail"

What a full channel does — the two GenStage :buffer_keep choices, named for the element that goes rather than the one that stays, plus the option of refusing to lose anything silently.

T
Source<T> = AsyncIterable<T> | Iterable<T>

Anything a Stream can be built from or flattened into: sync or async iterables (a web ReadableStream is async-iterable on every modern runtime).

Variables

v
ChannelOverflow: FailureFactory<"ChannelOverflow", { capacity: number; }>

A channel with overflow: 'fail' filled up: the consumer fell far enough behind that the buffer could not hold the difference, and dropping was not on the table.

v
T
Stream

The exported value: builders (Stream.from, Stream.unfold, Stream.lines) are the only entry points — there is no public constructor and no call form.