Skip to content

onlyAsync

onlyAsync<T>(iterable, description?, signal?): Promise<T>

Defined in: packages/core/src/iterable/async/only.ts:19

Returns the single element of an iterable, rejecting any other count.

The async counterpart of only. Use oneAsync where an empty iterable is acceptable.

Time complexity: O(1) — at most two elements are pulled, so this is safe on an endless stream.

T

MaybeAsyncIterable<T>

The iterable to read from, sync or async.

string = "item"

What the iterable holds, used in the error message.

AbortSignal

Aborts the read.

Promise<T>

The single element.

If the iterable is empty or holds more than one element.