UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

67 lines (65 loc) 2.94 kB
import { __asyncValues, __awaiter, __generator } from "tslib"; import { wrapWithAbort } from './operators/withabort.js'; import { throwIfAborted } from '../aborterror.js'; /** * Determines whether all elements of an async-iterable sequence satisfy 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>} options The options for a predicate for filtering, thisArg for binding and AbortSignal for cancellation. * @returns {Promise<boolean>} An async-iterable sequence containing a single element determining whether all elements in the * source sequence pass the test in the specified predicate. */ export function every(source, options) { var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { var signal, thisArg, predicate, i, _d, _e, _f, item, e_1_1; return __generator(this, function (_g) { switch (_g.label) { case 0: signal = options["signal"], thisArg = options["thisArg"], predicate = options["predicate"]; throwIfAborted(signal); i = 0; _g.label = 1; case 1: _g.trys.push([1, 7, 8, 13]); _d = true, _e = __asyncValues(wrapWithAbort(source, signal)); _g.label = 2; case 2: return [4 /*yield*/, _e.next()]; case 3: if (!(_f = _g.sent(), _a = _f.done, !_a)) return [3 /*break*/, 6]; _c = _f.value; _d = false; item = _c; return [4 /*yield*/, predicate.call(thisArg, item, i++, signal)]; case 4: if (!(_g.sent())) { return [2 /*return*/, false]; } _g.label = 5; case 5: _d = true; return [3 /*break*/, 2]; case 6: return [3 /*break*/, 13]; case 7: e_1_1 = _g.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 13]; case 8: _g.trys.push([8, , 11, 12]); if (!(!_d && !_a && (_b = _e.return))) return [3 /*break*/, 10]; return [4 /*yield*/, _b.call(_e)]; case 9: _g.sent(); _g.label = 10; case 10: return [3 /*break*/, 12]; case 11: if (e_1) throw e_1.error; return [7 /*endfinally*/]; case 12: return [7 /*endfinally*/]; case 13: return [2 /*return*/, true]; } }); }); } //# sourceMappingURL=every.js.map