Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / src/public-api / createAsyncIterator

Function: createAsyncIterator()

createAsyncIterator<T>(opts): () => AsyncIterator<T, undefined, undefined> & object

Defined in: projects/libraries/streamix/src/lib/utils/iterator.ts:49

Creates a factory that produces fresh AsyncIterator instances backed by an internal queue with producer-backpressure.

The register callback receives an Observer<T> whose next()/complete()/ error() methods push into the iterator's queue. next() returns a Promise<void> (or void) — the promise acts as a backpressure signal from the consumer: it resolves only when the consumer pulls the value with next() or __tryNext().

Each call of the returned factory function creates an independent iterator with its own buffer and subscription.

When lazy: true, registration is deferred until the consumer actually pulls (either next() or __tryNext>), which avoids hidden subscriptions for iterators that are constructed but never consumed.

Each call of the returned factory function creates an independent iterator with its own buffer and subscription.

Type Parameters

T

T

Value type.

Parameters

opts

Registration function and lazy mode.

register

(observer) => Subscription

conflate?

boolean

Returns

A function that creates a fresh AsyncIterator per call.

(): AsyncIterator<T, undefined, undefined> & object

Returns

AsyncIterator<T, undefined, undefined> & object

Released under the GNU AGPL v3 or later.