- 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.
推薦閱讀
- Moodle Administration Essentials
- Boost C++ Application Development Cookbook(Second Edition)
- 認(rèn)識(shí)編程:以Python語言講透編程的本質(zhì)
- OpenCV 3和Qt5計(jì)算機(jī)視覺應(yīng)用開發(fā)
- Magento 2 Development Cookbook
- The Computer Vision Workshop
- Java Web程序設(shè)計(jì)
- C語言程序設(shè)計(jì)
- Swift Playgrounds少兒趣編程
- Java EE企業(yè)級(jí)應(yīng)用開發(fā)教程(Spring+Spring MVC+MyBatis)
- UI設(shè)計(jì)基礎(chǔ)培訓(xùn)教程(全彩版)
- SEO教程:搜索引擎優(yōu)化入門與進(jìn)階(第3版)
- Puppet:Mastering Infrastructure Automation
- 體驗(yàn)之道:從需求到實(shí)踐的用戶體驗(yàn)實(shí)戰(zhàn)
- 程序員的英語