Skip to content

Type Alias: Stream<T>

Stream<T> = object

Defined in: abstractions/stream.ts:16

Represents a reactive stream that supports subscriptions and operator chaining.

A stream is a sequence of values over time that can be subscribed to for notifications. It is a foundational concept in reactive programming, providing a unified way to handle asynchronous data flows, such as events, data from APIs, or values from an async generator.

Type Parameters

T

T = any

The type of the values emitted by the stream.

Properties

type

type: "stream" | "subject"

Defined in: abstractions/stream.ts:22

A type discriminator to differentiate between stream types. stream indicates a cold, multicastable stream originating from a generator. subject would indicate a hot stream that can be manually controlled.


name?

optional name: string

Defined in: abstractions/stream.ts:26

An optional, human-readable name for the stream, useful for debugging and logging.


pipe

pipe: OperatorChain<T>

Defined in: abstractions/stream.ts:45

A method to chain stream operators.

This is a critical part of the stream's composability. It takes one or more Operators and returns a new Stream that applies each operator's transformation in order.

Example

typescript
const numberStream = createStream('numbers', async function*() {
  yield 1; yield 2; yield 3;
});

const doubledStream = numberStream.pipe(
  map(value => value * 2),
  filter(value => value > 3)
);

subscribe()

subscribe: (callback?) => Subscription

Defined in: abstractions/stream.ts:57

Subscribes a listener to the stream to receive emitted values.

Subscribing starts the stream's execution. Multiple subscriptions will multicast the same values to all listeners.

Parameters

callback?

An optional function or Receiver object to handle values, errors, and completion of the stream.

(value) => CallbackReturnType | Receiver<T>

Returns

Subscription

A Subscription object which can be used to unsubscribe and stop listening to the stream.


query()

query: () => Promise<T>

Defined in: abstractions/stream.ts:67

Queries the stream for its first emitted value and resolves when that value arrives.

This method is useful for scenarios where you only need a single value from the stream, such as a one-off API request or a single button click. It automatically unsubscribes after the first value is received.

Returns

Promise<T>

A promise that resolves with the first value emitted by the stream.

Released under the MIT License.