Skip to content

Instantly share code, notes, and snippets.

@qmzik
Created July 11, 2021 12:24
Show Gist options
  • Save qmzik/cd18301c877de19e27f192c578efbd74 to your computer and use it in GitHub Desktop.
Save qmzik/cd18301c877de19e27f192c578efbd74 to your computer and use it in GitHub Desktop.
class SafeSubscriber<T> {
closed = false;
constructor(private destination: Partial<Observer<T>>) {}
next(value: T) {
if (!this.closed) {
this.destination.next?.(value);
}
}
complete() {
if (!this.closed) {
this.closed = true;
this.destination.complete?.();
}
}
error(err: any) {
if (!this.closed) {
this.closed = true;
this.destination.error?.(err);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment