Skip to main content

Function: getAsync()

getAsync<Value>(asyncIterable): Promise<Value>

Returns a promise that resolves to the only value in asyncIterable if it contains exactly one value. Otherwise, returns a promise that rejects.

Type Parameters

Value

Parameters

asyncIterable: AsyncIterable<Value, any, any>

Returns

Promise<Value>

Example

console.log(await getAsync(asAsync([`sloth`])))
//=> sloth

try {
console.log(await getAsync(emptyAsync))
} catch {
console.log(`Oh no! It was empty...`)
}
//=> Oh no! It was empty...

try {
console.log(await getAsync(asAsync([1, `sloth`, 3])))
} catch {
console.log(`Oh no! It had more than one value...`)
}
//=> Oh no! It had more than one value...

Defined in

optionals.d.ts:170