Skip to content

Commit

Permalink
fix(retryWhen): preserve Subscriber chain in retryWhen()
Browse files Browse the repository at this point in the history
Fix retryWhen() operator to add its own Subscriber to the destination Subscriber, in order to avoid
breaking unsubscription chains.

For issue ReactiveX#875.
  • Loading branch information
staltz committed Dec 5, 2015
1 parent ac54093 commit 699d259
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/operator/retryWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class FirstRetryWhenSubscriber<T> extends Subscriber<T> {
constructor(public destination: Subscriber<T>,
public notifier: (errors: Observable<any>) => Observable<any>,
public source: Observable<T>) {
super(null);
super();
destination.add(this);
this.lastSubscription = this;
}

Expand All @@ -38,17 +39,19 @@ class FirstRetryWhenSubscriber<T> extends Subscriber<T> {
}

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);
Expand Down Expand Up @@ -88,9 +91,12 @@ class FirstRetryWhenSubscriber<T> extends Subscriber<T> {
}

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);
}
}

Expand Down

0 comments on commit 699d259

Please sign in to comment.