June 2017
Intermediate to advanced
400 pages
8h 44m
English
A close cousin of Observable.empty() is Observable.never(). The only difference between them is that it never calls onComplete(), forever leaving observers waiting for emissions but never actually giving any:
import io.reactivex.Observable; public class Launcher { public static void main(String[] args) { Observable<String> empty = Observable.never(); empty.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Done!")); sleep(5000); } public static void sleep(int millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); } } }
This Observable is primarily used for testing and not that often in production. We have to use sleep() here just like Observable.interval() ...
Read now
Unlock full access