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

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.

主站蜘蛛池模板: 临澧县| 佛冈县| 武定县| 大荔县| 新密市| 益阳市| 云南省| 鸡泽县| 湖州市| 崇明县| 彭山县| 民勤县| 惠来县| 澄江县| 收藏| 疏附县| 大邑县| 调兵山市| 正宁县| 延津县| 阳原县| 乐都县| 泰宁县| 独山县| 亚东县| 海南省| 崇文区| 宁波市| 梓潼县| 迭部县| 库车县| 嘉义县| 潞城市| 巴林左旗| 马鞍山市| 宜都市| 新乡县| 安庆市| 清水河县| 贵定县| 中阳县|