UNPKG

818 BJavaScriptView Raw
1import { wrapWithAbort } from './operators/withabort';
2import { throwIfAborted } from '../aborterror';
3/**
4 * Converts an existing async-iterable to a promise containing the array of values.
5 *
6 * @export
7 * @template TSource The type of elements in the source sequence.
8 * @param {AsyncIterable<TSource>} source The source sequence to convert to an array.
9 * @param {AbortSignal} [signal] An optional abort signal to cancel the operation at any time.
10 * @returns {Promise<TSource[]>} A promise containing all the items from the source sequence as an array.
11 */
12export async function toArray(source, signal) {
13 throwIfAborted(signal);
14 const results = [];
15 for await (const item of wrapWithAbort(source, signal)) {
16 results.push(item);
17 }
18 return results;
19}
20
21//# sourceMappingURL=toarray.mjs.map