Generic async iterable stream wrapper that provides abort control functionality. Allows for cancellation of streaming operations via AbortController.

Example

  const controller = new AbortController();
const stream = await Stream.createStream<MyType>(transformStream, controller);
for await (const item of stream) {
console.log(item);
}
// Later: controller.abort() to cancel
```;

Type Parameters

  • T

    Type of items in the stream

Implements

  • AsyncIterable<T>

Constructors

  • Creates a new Stream instance.

    Type Parameters

    • T

    Parameters

    • iterator: (() => AsyncIterator<T, any, undefined>)

      Function that returns an async iterator

        • (): AsyncIterator<T, any, undefined>
        • Returns AsyncIterator<T, any, undefined>

    • controller: AbortController

      Controller for aborting the stream

    Returns Stream<T>

Properties

controller: AbortController
iterator: (() => AsyncIterator<T, any, undefined>)

Function that returns an async iterator

Type declaration

    • (): AsyncIterator<T, any, undefined>
    • Returns AsyncIterator<T, any, undefined>

Methods

  • Implements the async iterator protocol for the stream.

    Returns AsyncIterator<T, any, undefined>

    Async iterator for the stream

  • Creates a Stream instance from a Transform stream.

    Type Parameters

    • T

      Type of items in the stream

    Parameters

    • stream: Transform

      Node.js Transform stream to wrap

    • controller: AbortController

      Controller for aborting the stream

    Returns Promise<Stream<T>>

    Promise resolving to a Stream instance