From 1c04b3494bb009064725c3977435e3172ccdf3eb Mon Sep 17 00:00:00 2001 From: Josep M Sobrepere Date: Sun, 23 Aug 2020 08:27:50 +0200 Subject: [PATCH] refactor(catchError): simplify implementation --- src/internal/operators/catchError.ts | 42 ++++------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/internal/operators/catchError.ts b/src/internal/operators/catchError.ts index f793d1b3de9..c4dcf76cc91 100644 --- a/src/internal/operators/catchError.ts +++ b/src/internal/operators/catchError.ts @@ -110,45 +110,15 @@ export function catchError>( ): OperatorFunction> { return (source: Observable) => lift(source, function (this: Subscriber, source: Observable) { - const subscriber = this; - const subscription = new Subscription(); - let innerSub: Subscription | null = null; - let syncUnsub = false; - let handledResult: Observable>; - - const handleError = (err: any) => { - try { - handledResult = from(selector(err, catchError(selector)(source))); - } catch (err) { - subscriber.error(err); - return; - } - }; - - innerSub = source.subscribe( - new CatchErrorSubscriber(subscriber, (err) => { - handleError(err); - if (handledResult) { - if (innerSub) { - innerSub.unsubscribe(); - innerSub = null; - subscription.add(handledResult.subscribe(subscriber)); - } else { - syncUnsub = true; - } + source.subscribe( + new CatchErrorSubscriber(this, (err) => { + try { + from(selector(err, catchError(selector)(source))).subscribe(this); + } catch (selectorErr) { + this.error(selectorErr); } }) ); - - if (syncUnsub) { - innerSub.unsubscribe(); - innerSub = null; - subscription.add(handledResult!.subscribe(subscriber)); - } else { - subscription.add(innerSub); - } - - return subscription; }); }