Skip to content

Commit f239184

Browse files
committed
fix: check for interop subscriptions
Closes #5237
1 parent c0a1bbe commit f239184

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/internal/operators/finalize.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ class FinallyOperator<T> implements Operator<T, T> {
6969
}
7070

7171
call(subscriber: Subscriber<T>, source: any): TeardownLogic {
72-
return source.subscribe(new FinallySubscriber(subscriber, this.callback));
72+
// The returned subscription will usually be the FinallySubscriber.
73+
// However, interop subscribers will be wrapped and for
74+
// unsubscriptions to chain correctly, the wrapper needs to be added, too.
75+
const finallySubscriber = new FinallySubscriber(subscriber, this.callback);
76+
const subscription = source.subscribe(finallySubscriber);
77+
if (subscription !== finallySubscriber) {
78+
subscription.add(finallySubscriber);
79+
}
80+
return subscription;
7381
}
7482
}
7583

0 commit comments

Comments
 (0)