UNPKG

1.11 kBJavaScriptView Raw
1import { wrapWithAbort } from './operators/withabort';
2import { throwIfAborted } from '../aborterror';
3/**
4 * Determines whether all elements of an async-iterable sequence satisfy a condition.
5 *
6 * @export
7 * @template T The type of the elements in the source sequence.
8 * @param {AsyncIterable<T>} source An async-iterable sequence whose elements to apply the predicate to.
9 * @param {FindOptions<T>} options The options for a predicate for filtering, thisArg for binding and AbortSignal for cancellation.
10 * @returns {Promise<boolean>} An async-iterable sequence containing a single element determining whether all elements in the
11 * source sequence pass the test in the specified predicate.
12 */
13export async function every(source, options) {
14 const { ['signal']: signal, ['thisArg']: thisArg, ['predicate']: predicate } = options;
15 throwIfAborted(signal);
16 let i = 0;
17 for await (const item of wrapWithAbort(source, signal)) {
18 if (!(await predicate.call(thisArg, item, i++, signal))) {
19 return false;
20 }
21 }
22 return true;
23}
24
25//# sourceMappingURL=every.mjs.map