Skip to content

Commit

Permalink
Fix cleanup observer blocking unsubscribe (2) (apollographql#6985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier committed Oct 15, 2020
1 parent 2b8ee34 commit 6dffbc1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/utilities/observables/Concast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,19 @@ export class Concast<T> extends Observable<T> {
observer: Observer<T>,
quietly?: boolean,
) {
if (this.observers.delete(observer) &&
this.observers.size < 1) {
if (quietly) return;
if (this.sub) {
this.sub.unsubscribe();
// In case anyone happens to be listening to this.promise, after
// this.observers has become empty.
this.reject(new Error("Observable cancelled prematurely"));
if (this.observers.delete(observer)) {
--this.addCount;

if (this.addCount < 1) {
if (quietly) return;
if (this.sub) {
this.sub.unsubscribe();
// In case anyone happens to be listening to this.promise, after
// this.observers has become empty.
this.reject(new Error("Observable cancelled prematurely"));
}
this.sub = null;
}
this.sub = null;
}
}

Expand Down

0 comments on commit 6dffbc1

Please sign in to comment.