toArray<T>(source: AsyncIterable<T>): Promise<T[]>
Creates an array from an async iterable.
import { toArray } from "./collections.ts"; async function* gen() { yield "foo"; yield "bar"; yield "baz"; } const array = await toArray(gen());
The array variable will be an array like ["foo", "bar", "baz"].
Note that its first parameter is assumed to be finite; otherwise, it will never return. The following example will never return:
import { toArray } from "./collections.ts"; import { count } from "./infinite.ts"; await toArray(count(0));
source: AsyncIterable<T>
An async iterable to create an array from. It must be finite.