A Lesson by Donn Felker
In this lesson you’ll learn how to dispose of a RxJava 2 observable stream using the
Disposable interface (source). You’ll be shown how to obtain a disposable instance via the
subscribe() method overloads. The
subscribe methods will be provided with a lambda expression that will consume the event. Since a lambda expression is used, a
LambaObservber (source) will be returned which you can use to dispose of the observable stream.
You’ll also be exposed to the
subscribeWith() operator which accepts an
Observer instance and you’ll learn how to provide a
DisposableObserver to this method in order to properly dispose of the observable sequence.
If you want to learn more about the history of the
isDisposed() method, please see this issue on the RxJava issues page on GitHub.
This lesson is demonstrated in Kotlin.
Code for the Lesson
Pro members: Log in to view the code for this lesson!
Lessons in this course
- RxJava 2 – compose() Operator
- RxJava 2 – Disposing of Subscriptions with Disposable
- RxJava Operators – Observable.just()
- RxJava: fromCallable vs defer – The differences between the two operators
- RxJava Operators – defer()
- RxJava Marble Diagrams
- RxJava fromCallable – Converting slow methods into an Observable
- RxJava Operators – observeOn
- RxJava Operators – subscribeOn
- Retrofit 2 with RxJava
- Grokking RxJava’s Observable.amb Operator
- Understanding the RxJava Observable.zip Operator
- RxJava Error Handling with Observable.error()
- Introduction to RxJava for Android Developers