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.
0unless a consumer fell behind. -
emit(value: T): boolean
Offers a value. Returns
falsewhen there is no room left — Node'swrite()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.
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: () => voiddropped: T | E,buffered: number
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
failorabort. -
overflow: Overflow
What to do once
capacityis reached: drop from either end, or'fail'— end the stream with a ChannelOverflowFailure element instead of losing anything quietly. Default'dropOldest'.
The failure element a 'fail' channel ends with.
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.
Anything a Stream can be built from or flattened into: sync or async iterables (a web ReadableStream is async-iterable on every modern runtime).
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.
The exported value: builders (Stream.from, Stream.unfold, Stream.lines) are the only
entry points — there is no public constructor and no call form.
Usage
import * as mod from "lib/stream/stream.ts";