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`.

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

Fixes ReactiveX#6364
  • Loading branch information
benlesh committed May 5, 2021
1 parent e797bd7 commit 9b6050b
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 9b6050b

Please sign in to comment.