Skip to content

teeAsync

teeAsync<T>(iterable, count?): AsyncIterableIterator<T, any, any>[]

Defined in: packages/core/src/iterable/async/tee.ts:24

Fans one iterable out to count independent iterators over the same elements.

The async counterpart of tee. Anything one branch has read that another has not yet reached is buffered — the span between the slowest and the fastest consumer, and nothing more.

Branches may be advanced concurrently. A pull from the source is shared: branches that need the same not-yet-read element all await the one in-flight read rather than issuing their own, so the source is never advanced twice for one element.

Time complexity: O(1) amortised per element per branch. Memory: O(span).

T

MaybeAsyncIterable<T>

The iterable to fan out, sync or async.

number = 2

How many branches to produce. Must be a non-negative integer.

AsyncIterableIterator<T, any, any>[]

One iterator per branch, each yielding every element of the source.

If count is not a non-negative integer.