Created
July 11, 2021 12:24
-
-
Save qmzik/cd18301c877de19e27f192c578efbd74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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