@reactivex/ix-es2015-cjs
Version:
The Interactive Extensions for JavaScript
83 lines (81 loc) • 3.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.catchError = exports.CatchWithAsyncIterable = 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("./withabort.js");
const aborterror_js_1 = require("../../aborterror.js");
/** @ignore */
class CatchWithAsyncIterable extends asynciterablex_js_1.AsyncIterableX {
constructor(source, handler) {
super();
this._source = source;
this._handler = handler;
}
[Symbol.asyncIterator](signal) {
return tslib_1.__asyncGenerator(this, arguments, function* _a() {
var _b, e_1, _c, _d;
(0, aborterror_js_1.throwIfAborted)(signal);
let err;
let hasError = false;
const source = (0, withabort_js_1.wrapWithAbort)(this._source, signal);
const it = source[Symbol.asyncIterator]();
while (1) {
let c = {};
try {
c = yield tslib_1.__await(it.next());
if (c.done) {
yield tslib_1.__await((0, returniterator_js_1.returnAsyncIterator)(it));
break;
}
}
catch (e) {
err = yield tslib_1.__await(this._handler(e, signal));
hasError = true;
yield tslib_1.__await((0, returniterator_js_1.returnAsyncIterator)(it));
break;
}
yield yield tslib_1.__await(c.value);
}
if (hasError) {
try {
for (var _e = true, _f = tslib_1.__asyncValues((0, withabort_js_1.wrapWithAbort)(err, signal)), _g; _g = yield tslib_1.__await(_f.next()), _b = _g.done, !_b; _e = true) {
_d = _g.value;
_e = false;
const item = _d;
yield yield tslib_1.__await(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_e && !_b && (_c = _f.return)) yield tslib_1.__await(_c.call(_f));
}
finally { if (e_1) throw e_1.error; }
}
}
});
}
}
exports.CatchWithAsyncIterable = CatchWithAsyncIterable;
/**
* Continues an async-iterable sequence that is terminated by an exception with the
* async-iterable sequence produced by the handler.
*
* @template TSource The type of the elements in the source sequence.
* @template TResult The type of elements from the handler function.
* @param {((
* error: any,
* signal?: AbortSignal
* ) => AsyncIterable<TResult> | Promise<AsyncIterable<TResult>>)} handler Error handler function, producing another async-iterable sequence.
* @returns {(OperatorAsyncFunction<TSource, TSource | TResult>)} An operator which continues an async-iterable sequence that is terminated by
* an exception with the specified handler.
*/
function catchError(handler) {
return function catchWithOperatorFunction(source) {
return new CatchWithAsyncIterable(source, handler);
};
}
exports.catchError = catchError;
//# sourceMappingURL=catcherror.js.map