UNPKG

@reactivex/ix-es2015-cjs

Version:

The Interactive Extensions for JavaScript

79 lines (77 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.catchError = exports.catchAll = exports.CatchAllAsyncIterable = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("./asynciterablex.js"); const returniterator_js_1 = require("../util/returniterator.js"); const withabort_js_1 = require("./operators/withabort.js"); const aborterror_js_1 = require("../aborterror.js"); /** @ignore */ class CatchAllAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(source) { super(); this._source = source; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { (0, aborterror_js_1.throwIfAborted)(signal); let error = null; let hasError = false; for (const source of this._source) { const it = (0, withabort_js_1.wrapWithAbort)(source, signal)[Symbol.asyncIterator](); error = null; hasError = false; while (1) { let c = {}; try { const { done, value } = yield tslib_1.__await(it.next()); if (done) { yield tslib_1.__await((0, returniterator_js_1.returnAsyncIterator)(it)); break; } c = value; } catch (e) { error = e; hasError = true; yield tslib_1.__await((0, returniterator_js_1.returnAsyncIterator)(it)); break; } yield yield tslib_1.__await(c); } if (!hasError) { break; } } if (hasError) { throw error; } }); } } exports.CatchAllAsyncIterable = CatchAllAsyncIterable; /** * Continues an async-iterable sequence that is terminated by an exception with the next async-iterable sequence. * * @template T The type of the elements in the source and handler sequences. * @param {Iterable<AsyncIterable<T>>} source async-iterable sequences to catch exceptions for. * @returns {AsyncIterableX<T>} An async-iterable sequence containing elements from consecutive source * sequences until a source sequence terminates successfully. */ function catchAll(source) { return new CatchAllAsyncIterable(source); } exports.catchAll = catchAll; /** * Continues an async-iterable sequence that is terminated by an exception with the next async-iterable sequence. * * @template T The type of the elements in the source and handler sequences. * @param {...AsyncIterable<T>[]} args async-iterable sequences to catch exceptions for. * @returns {AsyncIterableX<T>} An async-iterable sequence containing elements from consecutive source * sequences until a source sequence terminates successfully. */ function catchError(...args) { return new CatchAllAsyncIterable(args); } exports.catchError = catchError; //# sourceMappingURL=catcherror.js.map