- Learning RxJava
- Thomas Nield
- 135字
- 2021-07-02 22:22:53
Observable.never()
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() because the main thread is not going to wait for it after kicking it off. In this case, we just use sleep() for five seconds to prove that no emissions are coming from it. Then, the application will quit.
推薦閱讀
- Java系統分析與架構設計
- Visual Basic編程:從基礎到實踐(第2版)
- Manga Studio Ex 5 Cookbook
- Apache Spark 2 for Beginners
- Learning Linux Binary Analysis
- Elastic Stack應用寶典
- Mastering Python Networking
- 學習OpenCV 4:基于Python的算法實戰(zhàn)
- Emgu CV Essentials
- 零基礎學C語言第2版
- INSTANT Apache Hive Essentials How-to
- Get Your Hands Dirty on Clean Architecture
- Cinder:Begin Creative Coding
- VC++ 2008專題應用程序開發(fā)實例精講
- Learning QGIS(Second Edition)