Canceling Sequences
In RxJS we can cancel a running Observable. This is an advantage over other asynchronous forms of communication, such as callbacks and promises, which can’t be directly canceled once they’re called (some promise implementations support cancellation, though).
There are two main ways we can cancel an Observable: implicitly and explicitly.
Explicit Cancellation: The Disposable
Observables themselves don’t have a method to get canceled. Instead, whenever we subscribe to an Observable we get a Disposable object that represents that particular subscription. We can then call the method dispose in that object, and that subscription will stop receiving notifications from the Observable.
In the following example, we subscribe ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access