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 | export async function sum(source, options) {
|
13 | const { ['selector']: selector = identityAsync, ['signal']: signal, ['thisArg']: thisArg, } = options || {};
|
14 | throwIfAborted(signal);
|
15 | let value = 0;
|
16 | for await (const item of wrapWithAbort(source, signal)) {
|
17 | value += await selector.call(thisArg, item, signal);
|
18 | }
|
19 | return value;
|
20 | }
|
21 |
|
22 |
|