fromAsync

Bun

Symbol

ArrayConstructor.fromAsync

fromAsync<T>(iterableOrArrayLike: AsyncIterable<T, any, any> | Iterable<T | PromiseLike<T>, any, any> | ArrayLike<T | PromiseLike<T>>): Promise<T[]>

Creates an array from an async iterator or iterable object.

@param iterableOrArrayLike

An async iterator or array-like object to convert to an array.

fromAsync<T, U>(iterableOrArrayLike: AsyncIterable<T, any, any> | Iterable<T, any, any> | ArrayLike<T>, mapFn: (value: Awaited<T>, index: number) => U, thisArg?: any): Promise<Awaited<U>[]>

Creates an array from an async iterator or iterable object.

@param iterableOrArrayLike

An async iterator or array-like object to convert to an array.

@param thisArg

Value of 'this' used when executing mapfn.

fromAsync<T>(arrayLike: AsyncIterable<T, any, any> | Iterable<T, any, any> | ArrayLike<T>): Promise<Awaited<T>[]>

Create an array from an iterable or async iterable object. Values from the iterable are awaited.

await Array.fromAsync([1]); // [1]
await Array.fromAsync([Promise.resolve(1)]); // [1]
await Array.fromAsync((async function*() { yield 1 })()); // [1]
@param arrayLike

The iterable or async iterable to convert to an array.

@returns

A Promise whose fulfillment is a new Array instance containing the values from the iterator.

fromAsync<T, U>(arrayLike: AsyncIterable<T, any, any> | Iterable<T, any, any> | ArrayLike<T>, mapFn?: (value: T, index: number) => U, thisArg?: any): Promise<Awaited<U>[]>

Create an array from an iterable or async iterable object. Values from the iterable are awaited. Results of the map function are also awaited.

await Array.fromAsync([1]); // [1]
await Array.fromAsync([Promise.resolve(1)]); // [1]
await Array.fromAsync((async function*() { yield 1 })()); // [1]
await Array.fromAsync([1], (n) => n + 1); // [2]
await Array.fromAsync([1], (n) => Promise.resolve(n + 1)); // [2]
@param arrayLike

The iterable or async iterable to convert to an array.

@param mapFn

A mapper function that transforms each element of arrayLike after awaiting them.

@param thisArg

The this to which mapFn is bound.

@returns

A Promise whose fulfillment is a new Array instance containing the values from the iterator.