Skip to content

Commit

Permalink
fix: Observable teardowns now properly called if `useDeprecatedSynchr…
Browse files Browse the repository at this point in the history
…onousErrorHandling` is `true`. (#6365)

Resolves an issue where teardowns returned by the Observable initializer were not being registered with the subscriber.

Fixes #6364
  • Loading branch information
benlesh committed May 5, 2021
1 parent e797bd7 commit e19e104
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions spec/Observable-spec.ts
Expand Up @@ -810,6 +810,24 @@ describe('Observable', () => {
}).not.to.throw();
});

it('should call teardown if sync unsubscribed', () => {
let called = false;
const observable = new Observable(() => () => (called = true));
const subscription = observable.subscribe();
subscription.unsubscribe();

expect(called).to.be.true;
});

it('should call registered teardowns if sync unsubscribed', () => {
let called = false;
const observable = new Observable((subscriber) => subscriber.add(() => called = true));
const subscription = observable.subscribe();
subscription.unsubscribe();

expect(called).to.be.true;
});

afterEach(() => {
config.useDeprecatedSynchronousErrorHandling = false;
});
Expand Down
2 changes: 1 addition & 1 deletion src/internal/Observable.ts
Expand Up @@ -252,7 +252,7 @@ export class Observable<T> implements Subscribable<T> {
subscriber.add(operator.call(subscriber, this.source));
} else {
try {
this._subscribe(subscriber);
subscriber.add(this._subscribe(subscriber));
} catch (err) {
localSubscriber.__syncError = err;
}
Expand Down

0 comments on commit e19e104

Please sign in to comment.