@xo-cash/utils
    Preparing search index...

    Class AsyncPushIterator<T>

    An async iterable queue that bridges push-based producers and pull-based consumers.

    Composes an internal ReadableStream instead of extending it, so producers call push while consumers use standard async iteration (for await...of).

    const messages = new AsyncPushIterator<SSEvent>();

    // Producer (elsewhere)
    messages.push(event);

    // Consumer
    for await (const event of messages) {
    handle(event);
    }

    Symbol.asyncIterator returns stream.values({ preventCancel: true }) so breaking out of for await...of does not cancel the underlying stream. That matters for long-lived sessions where the producer keeps pushing after a consumer stops reading early (for example, test helpers that only collect a fixed count).

    Type Parameters

    • T
    Index
    • Returns an async iterator over the composed stream.

      Uses preventCancel: true so early break from for await...of does not close the stream and block later pushes.

      Because values are discarded after being read, only a single consumer is supported. Additional consumers will receive a stream lock error. Unread values will be preserved until close is called.

      Returns AsyncIterableIterator<T>

    • Ends the stream.

      Marks the iterator closed so future push calls are ignored. Buffered values are still yielded before iteration completes.

      Returns void

    • Causes any future interactions with the associated stream to error with error. Calling this will also clear the pending values immediately, so iterators that were listening will not receive them.

      Parameters

      • error: Error

        The error to throw from the stream.

      Returns void

    • Enqueues a value for the consumer.

      After close, pushes are silently dropped.

      Parameters

      • value: T

        The next value to yield from the iterator.

      Returns void