February 2020
Intermediate to advanced
412 pages
9h 36m
English
Although this may not seem useful yet, it is sometimes helpful to create an Observable that emits nothing and calls onComplete():
import io.reactivex.rxjava3.core.Observable;public class Ch2_20 { public static void main(String[] args) { Observable<String> empty = Observable.empty(); empty.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Done!")); }}
The output is as follows:
Done!
Note that no emissions were printed because there were none. It went straight to emitting the onComplete event processed by the third parameter of the subscribe(Consumer<String> onNext, Consumer<Throwable> onError, Action onComplete) method, which printed the Done! message.
Empty observables typically represent ...
Read now
Unlock full access