Skip to content

Commit e19e104

Browse files
authoredMay 5, 2021
fix: Observable teardowns now properly called if useDeprecatedSynchronousErrorHandling is true. (#6365)
Resolves an issue where teardowns returned by the Observable initializer were not being registered with the subscriber. Fixes #6364
1 parent e797bd7 commit e19e104

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
 

Diff for: ‎spec/Observable-spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,24 @@ describe('Observable', () => {
810810
}).not.to.throw();
811811
});
812812

813+
it('should call teardown if sync unsubscribed', () => {
814+
let called = false;
815+
const observable = new Observable(() => () => (called = true));
816+
const subscription = observable.subscribe();
817+
subscription.unsubscribe();
818+
819+
expect(called).to.be.true;
820+
});
821+
822+
it('should call registered teardowns if sync unsubscribed', () => {
823+
let called = false;
824+
const observable = new Observable((subscriber) => subscriber.add(() => called = true));
825+
const subscription = observable.subscribe();
826+
subscription.unsubscribe();
827+
828+
expect(called).to.be.true;
829+
});
830+
813831
afterEach(() => {
814832
config.useDeprecatedSynchronousErrorHandling = false;
815833
});

Diff for: ‎src/internal/Observable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class Observable<T> implements Subscribable<T> {
252252
subscriber.add(operator.call(subscriber, this.source));
253253
} else {
254254
try {
255-
this._subscribe(subscriber);
255+
subscriber.add(this._subscribe(subscriber));
256256
} catch (err) {
257257
localSubscriber.__syncError = err;
258258
}

0 commit comments

Comments
 (0)
Please sign in to comment.