Skip to content

Commit b429dac

Browse files
staltzbenlesh
authored andcommitted
fix(retry): preserve Subscriber chain in retry()
Fix retry() operator to add its own Subscriber to the destination Subscriber, in order to avoid breaking unsubscription chains. For issue #875.
1 parent d3cf59c commit b429dac

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/operator/retry.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class FirstRetrySubscriber<T> extends Subscriber<T> {
2323
constructor(public destination: Subscriber<T>,
2424
private count: number,
2525
private source: Observable<T>) {
26-
super(null);
26+
super();
27+
destination.add(this);
2728
this.lastSubscription = this;
2829
}
2930

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

3435
error(error?) {
3536
if (!this.isUnsubscribed) {
36-
super.unsubscribe();
37+
this.unsubscribe();
3738
this.resubscribe();
3839
}
3940
}
4041

4142
_complete() {
42-
super.unsubscribe();
43+
this.unsubscribe();
4344
this.destination.complete();
4445
}
4546

46-
unsubscribe() {
47-
const lastSubscription = this.lastSubscription;
48-
if (lastSubscription === this) {
49-
super.unsubscribe();
50-
} else {
51-
lastSubscription.unsubscribe();
52-
}
53-
}
54-
5547
resubscribe(retried: number = 0) {
56-
this.lastSubscription.unsubscribe();
48+
const { lastSubscription, destination } = this;
49+
destination.remove(lastSubscription);
50+
lastSubscription.unsubscribe();
5751
const nextSubscriber = new RetryMoreSubscriber(this, this.count, retried + 1);
5852
this.lastSubscription = this.source.subscribe(nextSubscriber);
53+
destination.add(this.lastSubscription);
5954
}
6055
}
6156

0 commit comments

Comments
 (0)