oneAsync
oneAsync<
T>(iterable,description?,signal?):Promise<T|undefined>
Defined in: packages/core/src/iterable/async/one.ts:21
Returns the single element of an iterable, or undefined when it is empty,
rejecting any larger count.
The async counterpart of one, and the tolerant half of the pair onlyAsync
completes.
Time complexity: O(1) — at most two elements are pulled, so this is safe on an endless stream.
Type Parameters
Section titled “Type Parameters”T extends DefinedValue
Parameters
Section titled “Parameters”iterable
Section titled “iterable”The iterable to read from, sync or async.
description?
Section titled “description?”string = "item"
What the iterable holds, used in the error message.
signal?
Section titled “signal?”AbortSignal
Aborts the read.
Returns
Section titled “Returns”Promise<T | undefined>
The single element, or undefined if there is none.
Throws
Section titled “Throws”If the iterable holds more than one element.