Skip to content

Commit

Permalink
fix(retry): preserve Subscriber chain in retry()
Browse files Browse the repository at this point in the history
Fix retry() 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
1 parent d3cf59c commit b429dac
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/operator/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class FirstRetrySubscriber<T> extends Subscriber<T> {
constructor(public destination: Subscriber<T>,
private count: number,
private source: Observable<T>) {
super(null);
super();
destination.add(this);
this.lastSubscription = this;
}

Expand All @@ -33,29 +34,23 @@ class FirstRetrySubscriber<T> extends Subscriber<T> {

error(error?) {
if (!this.isUnsubscribed) {
super.unsubscribe();
this.unsubscribe();
this.resubscribe();
}
}

_complete() {
super.unsubscribe();
this.unsubscribe();
this.destination.complete();
}

unsubscribe() {
const lastSubscription = this.lastSubscription;
if (lastSubscription === this) {
super.unsubscribe();
} else {
lastSubscription.unsubscribe();
}
}

resubscribe(retried: number = 0) {
this.lastSubscription.unsubscribe();
const { lastSubscription, destination } = this;
destination.remove(lastSubscription);
lastSubscription.unsubscribe();
const nextSubscriber = new RetryMoreSubscriber(this, this.count, retried + 1);
this.lastSubscription = this.source.subscribe(nextSubscriber);
destination.add(this.lastSubscription);
}
}

Expand Down

0 comments on commit b429dac

Please sign in to comment.