Skip to content

Function: createStream()

createStream<T>(name, generatorFn): Stream<T>

Defined in: abstractions/stream.ts:88

Creates a multicast stream from an async generator function.

A multicast stream (also known as a hot stream) starts executing its work (running the generatorFn) when the first subscriber joins. All subsequent subscriptions will share the same underlying generator execution, receiving the same values from that single source. This is different from a typical cold stream, where each subscription would trigger a new, independent execution.

The stream manages the subscription lifecycle and performs graceful teardown of the generator when there are no more active subscribers.

Type Parameters

T

T

The type of the values that the stream will emit.

Parameters

name

string

A human-readable name for the stream, useful for debugging.

generatorFn

() => AsyncGenerator<T, void, unknown>

An async generator function that defines the source of the stream's values. The generator's yield statements push values to the stream.

Returns

Stream<T>

A new Stream instance.

Released under the MIT License.