UNPKG

ix

Version:

The Interactive Extensions for JavaScript

42 lines (40 loc) 1.71 kB
import { __asyncValues, __awaiter } from "tslib"; import { wrapWithAbort } from './operators/withabort.mjs'; import { throwIfAborted } from '../aborterror.mjs'; /** * Determines whether any element of an async-iterable sequence satisfies a condition. * * @template T The type of the elements in the source sequence. * @param {AsyncIterable<T>} source An async-iterable sequence whose elements to apply the predicate to. * @param {FindOptions<T, S>} options The options which includes a required predicate, an optional * thisArg for binding, and an abort signal for cancellation. * @returns {Promise<boolean>} A promise with a boolean determining whether any elements in the source sequence * pass the test in the specified predicate. */ export function some(source, options) { var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function* () { const { ['signal']: signal, ['thisArg']: thisArg, ['predicate']: predicate } = options; throwIfAborted(signal); let i = 0; try { for (var _d = true, _e = __asyncValues(wrapWithAbort(source, signal)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) { _c = _f.value; _d = false; const item = _c; if (yield predicate.call(thisArg, item, i++, signal)) { return true; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield _b.call(_e); } finally { if (e_1) throw e_1.error; } } return false; }); } //# sourceMappingURL=some.mjs.map