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:315
Better Array.fromAsync.
Returns a readonly array and awaits promised items from sync or async iterables.
Awaiting sync and async iterables
import { assertEqual, assertType, arrayFromAsync } from "@evolu/common";
const fromIterable = await arrayFromAsync([
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
]);
assertEqual(fromIterable, [1, 2, 3]);
const fromAsyncIterable = await arrayFromAsync(
(async function* (): AsyncGenerator<number> {
await Promise.resolve();
yield 1;
yield 2;
})(),
);
assertEqual(fromAsyncIterable, [1, 2]);
assertType<ReadonlyArray<number>, typeof fromAsyncIterable>();
Unlike Array.fromAsync, there's no map parameter — map the result with
mapArray or use
iterator helpers
directly on iterables.