1 | import { wrapWithAbort } from './operators/withabort';
|
2 | import { throwIfAborted } from '../aborterror';
|
3 | /**
|
4 | * Converts the existing async-iterable into a promise which resolves a Set.
|
5 | *
|
6 | * @export
|
7 | * @template TSource The type of elements in the source sequence.
|
8 | * @param {AsyncIterable<TSource>} source The async-iterable to convert into a set.
|
9 | * @param {AbortSignal} [signal] An optional abort signal to cancel the operation at any time.
|
10 | * @returns {Promise<Set<TSource>>} A promise which contains a Set with all the elements from the async-iterable.
|
11 | */
|
12 | export async function toSet(source, signal) {
|
13 | throwIfAborted(signal);
|
14 | const set = new Set();
|
15 | for await (const item of wrapWithAbort(source, signal)) {
|
16 | set.add(item);
|
17 | }
|
18 | return set;
|
19 | }
|
20 |
|
21 | //# sourceMappingURL=toset.mjs.map
|