Library API
    Preparing search index...

    Class Reactive<T>

    Universal, zero-dependency async reactive stream combining push-based event emission and pull-based AsyncIterable iteration with native TC39 resource management (using / await using) and Garbage Collection finalization safety.

    const stream = new Reactive<number>();

    // Consumer 1: Pull-mode
    queueMicrotask(async () => {
    const val = await stream.pull(); // 42
    });

    // Producer: Push-mode
    stream.push(42);

    Type Parameters

    • T

    Implements

    • AsyncIterable<T>
    • AsyncIterator<T, void, unknown>
    • Disposable
    • AsyncDisposable
    Index
    • Type Parameters

      • T

      Parameters

      Returns Reactive<T>

    • get isReactive(): boolean

      Identifies this object as a Reactive instance

      Returns boolean

    • get state(): State

      Returns the operational state of this stream

      Returns State

    • Asynchronous disposal hook (await using stream = new Reactive())

      Returns Promise<void>

    • Returns this instance as an AsyncIterator

      Returns AsyncIterator<T, void, unknown>

    • Synchronous disposal hook (using stream = new Reactive())

      Returns void

    • Broadcasts a value to ALL pending pull waiters and push listeners simultaneously.

      Parameters

      • value: T

        The value to broadcast

      Returns boolean

      True if the value was successfully emitted; false if completed or inactive

      cast

    • Casts a value to ALL pending pull waiters and push listeners simultaneously (multicast fan-out).

      Parameters

      • value: T

        The value to cast across all consumers

      Returns boolean

      True if the value was successfully emitted; false if completed or inactive

    • Completes and closes the reactive stream.

      Parameters

      • OptionalterminalValue: T

        Optional final value to emit prior to closing

      Returns void

    • Emits a value to active pull-mode consumers or push-mode listeners.

      Parameters

      • value: T

        The value to emit

      Returns boolean

      True if the value was successfully emitted; false if completed or inactive

      push

    • Emits an error to registered error listeners or rejects pending pull consumers.

      Parameters

      • err: Error

        The error instance to dispatch

      Returns void

    • Advances the async iterator to the next available item.

      Returns Promise<IteratorResult<T, void>>

    • Unsubscribes a previously registered event listener.

      Parameters

      • event: EventType

        Event name

      • listener: Function

        Listener function to remove

      Returns this

      this for chaining

    • Subscribes to stream events with optional AbortSignal and once configuration. Returns a disposable Subscription handle for explicit resource management (using sub = ...).

      Parameters

      • event: "data"

        'data', 'error', 'end', or 'stop'

      • listener: Listener<T>

        Callback to invoke when the event fires

      • Optionaloptions: SubscriptionOptions

        Subscription options (AbortSignal, once)

      Returns ReactiveSubscription

      A disposable Subscription handle

    • Subscribes to stream events with optional AbortSignal and once configuration. Returns a disposable Subscription handle for explicit resource management (using sub = ...).

      Parameters

      • event: "error"

        'data', 'error', 'end', or 'stop'

      • listener: ErrorListener

        Callback to invoke when the event fires

      • Optionaloptions: SubscriptionOptions

        Subscription options (AbortSignal, once)

      Returns ReactiveSubscription

      A disposable Subscription handle

    • Subscribes to stream events with optional AbortSignal and once configuration. Returns a disposable Subscription handle for explicit resource management (using sub = ...).

      Parameters

      • event: "end" | "stop"

        'data', 'error', 'end', or 'stop'

      • listener: EndListener

        Callback to invoke when the event fires

      • Optionaloptions: SubscriptionOptions

        Subscription options (AbortSignal, once)

      Returns ReactiveSubscription

      A disposable Subscription handle

    • Subscribes to a single event occurrence.

      Parameters

      Returns ReactiveSubscription

      A disposable Subscription handle

    • Subscribes to a single event occurrence.

      Parameters

      Returns ReactiveSubscription

      A disposable Subscription handle

    • Subscribes to a single event occurrence.

      Parameters

      Returns ReactiveSubscription

      A disposable Subscription handle

    • Pulls the next available value directly from the stream.

      Returns Promise<T | undefined>

      A promise resolving to the next item T, or undefined if completed

    • Pushes data into the stream (producer mode) or registers a listener (consumer mode).

      Parameters

      • value: T

      Returns boolean

      True if the value was successfully emitted; false if completed or inactive; Reactive.Subscription if registering a listener

    • Pushes data into the stream (producer mode) or registers a listener (consumer mode).

      Parameters

      Returns ReactiveSubscription

      True if the value was successfully emitted; false if completed or inactive; Reactive.Subscription if registering a listener

    • Closes the async iterator and marks the stream as completed.

      Returns Promise<IteratorResult<T, void>>

    • Alias for complete().

      Parameters

      • OptionalterminalValue: T

        Optional final value to emit prior to closing

      Returns void

      complete

    • Throws an error into the stream, rejecting pending waiters and stopping the stream.

      Parameters

      • Optionalerr: any

      Returns Promise<IteratorResult<T, void>>

    • Returns a new Reactive stream that mirrors the source but completes automatically when the given notifier (AbortSignal, Promise, or trigger Reactive stream) fires.

      Parameters

      • notifier: Promise<any> | AbortSignal | Reactive<any>

        An AbortSignal, Promise, or Reactive stream bounding this stream's lifecycle.

      Returns Reactive<T>

      A new Reactive stream

    • Creates a Reactive stream from an iterable, async iterable, or Promise.

      Type Parameters

      • V

      Parameters

      • source: Iterable<V, any, any> | AsyncIterable<V, any, any> | Promise<V>

        The source collection or promise

      • Optionaloptions: Options<V>

        Optional configuration options

      Returns Reactive<V>

      A Reactive stream instance