官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 老河口市| 雅安市| 西盟| 平阳县| 宜良县| 深水埗区| 甘洛县| 马公市| 邛崃市| 犍为县| 页游| 贡觉县| 遂溪县| 盐山县| 邯郸市| 宝应县| 南开区| 论坛| 安塞县| 绥滨县| 关岭| 临潭县| 朝阳县| 丹棱县| 元江| 石阡县| 商河县| 仁寿县| 囊谦县| 石林| 伊川县| 资中县| 丰台区| 龙海市| 潮安县| 六安市| 康平县| 东山县| 广州市| 新丰县| 靖江市|