"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.catchError = void 0;
const Observable_js_1 = require("../Observable.js");
function catchError(selector) {
    return (source) => new Observable_js_1.Observable((destination) => {
        let innerSub = null;
        let syncUnsub = false;
        let handledResult;
        innerSub = source.subscribe((0, Observable_js_1.operate)({
            destination,
            error: (err) => {
                handledResult = (0, Observable_js_1.from)(selector(err, catchError(selector)(source)));
                if (innerSub) {
                    innerSub.unsubscribe();
                    innerSub = null;
                    handledResult.subscribe(destination);
                }
                else {
                    syncUnsub = true;
                }
            },
        }));
        if (syncUnsub) {
            innerSub.unsubscribe();
            innerSub = null;
            handledResult.subscribe(destination);
        }
    });
}
exports.catchError = catchError;//# sourceMappingURL=http://go/sourcemap/sourcemaps/fc2563ec93d793fc275eef734405a4fdf8b47b20/node_modules/rxjs/dist/cjs/internal/operators/catchError.js.map