Created
July 11, 2021 12:23
-
-
Save qmzik/65664ad3e1c6f9bcba1d63d0751bbc14 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); // Note the ?. check here. | |
} | |
} | |
complete() { | |
if (!this.closed) { | |
this.closed = true; | |
this.destination.complete?.(); // And here. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment