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 #875.
  • Loading branch information
staltz authored and benlesh committed Dec 8, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 52ac86c commit c9cb958
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
@@ -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;
}

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

0 comments on commit c9cb958

Please sign in to comment.