API reference › @evolu/common › Array › arrayFromAsync
function arrayFromAsync<T>(
iterable: AsyncIterable<T, any, any> | Iterable<T | PromiseLike<T>, any, any>,
): Promise<readonly T[]>;
Defined in: packages/common/src/Array.ts:259
Better Array.fromAsync.
Returns a readonly array and awaits promised items from sync or async iterables.
Awaiting sync and async iterables
import { arrayFromAsync } from "@evolu/common";
const fromIterable = await arrayFromAsync(new Set([1, 2, 3]));
expect(fromIterable).toEqual([1, 2, 3]);
const fromAsyncIterable = await arrayFromAsync(
(async function* () {
yield Promise.resolve(1);
yield Promise.resolve(2);
})(),
);
expect(fromAsyncIterable).toEqual([1, 2]);
expectTypeOf(fromAsyncIterable).toEqualTypeOf<ReadonlyArray<number>>();
Unlike Array.fromAsync, there's no map parameter — map the result with
mapArray or use
iterator helpers
directly on iterables.