1 | import { identityAsync } from '../util/identity';
|
2 | import { wrapWithAbort } from './operators/withabort';
|
3 | import { throwIfAborted } from '../aborterror';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export async function toMap(source, options) {
|
16 | const { ['signal']: signal, ['elementSelector']: elementSelector = identityAsync, ['keySelector']: keySelector = identityAsync, } = options || {};
|
17 | throwIfAborted(signal);
|
18 | const map = new Map();
|
19 | for await (const item of wrapWithAbort(source, signal)) {
|
20 | const value = await elementSelector(item, signal);
|
21 | const key = await keySelector(item, signal);
|
22 | map.set(key, value);
|
23 | }
|
24 | return map;
|
25 | }
|
26 |
|
27 |
|