From c9cb958e8ce1b0cc68d7d4dd3341948f2efed4fd Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Sat, 5 Dec 2015 14:08:55 +0200 Subject: [PATCH] fix(retryWhen): preserve Subscriber chain in retryWhen() Fix retryWhen() operator to add its own Subscriber to the destination Subscriber, in order to avoid breaking unsubscription chains. For issue #875. --- src/operator/retryWhen.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/operator/retryWhen.ts b/src/operator/retryWhen.ts index f1818ddf00..1f58285f4f 100644 --- a/src/operator/retryWhen.ts +++ b/src/operator/retryWhen.ts @@ -29,7 +29,8 @@ class FirstRetryWhenSubscriber extends Subscriber { constructor(public destination: Subscriber, public notifier: (errors: Observable) => Observable, public source: Observable) { - super(null); + super(); + destination.add(this); this.lastSubscription = this; } @@ -38,17 +39,19 @@ class FirstRetryWhenSubscriber extends Subscriber { } error(err?) { + const destination = this.destination; if (!this.isUnsubscribed) { super.unsubscribe(); if (!this.retryNotifications) { this.errors = new Subject(); const notifications = tryCatch(this.notifier).call(this, this.errors); if (notifications === errorObject) { - this.destination.error(errorObject.e); + destination.error(errorObject.e); } else { this.retryNotifications = notifications; const notificationSubscriber = new RetryNotificationSubscriber(this); this.notificationSubscription = notifications.subscribe(notificationSubscriber); + destination.add(this.notificationSubscription); } } this.errors.next(err); @@ -88,9 +91,12 @@ class FirstRetryWhenSubscriber extends Subscriber { } resubscribe() { - this.lastSubscription.unsubscribe(); + const { destination, lastSubscription } = this; + destination.remove(lastSubscription); + lastSubscription.unsubscribe(); const nextSubscriber = new MoreRetryWhenSubscriber(this); this.lastSubscription = this.source.subscribe(nextSubscriber); + destination.add(this.lastSubscription); } }