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

Completable

Completable is simply concerned with an action being executed, but it does not receive any emissions. Logically, it does not have  onNext() or onSuccess() to receive emissions, but it does have onError() and onComplete():

    interface CompletableObserver<T> {
void onSubscribe(Disposable d);
void onComplete();
void onError(Throwable error);
}

Completable is something you likely will not use often. You can construct one quickly by calling Completable.complete() or Completable.fromRunnable(). The former will immediately call onComplete() without doing anything, while fromRunnable() will execute the specified action before calling onComplete():

    import io.reactivex.Completable;

public class Launcher {

public static void main(String[] args) {

Completable.fromRunnable(() -> runProcess())
.subscribe(() -> System.out.println("Done!"));

}
public static void runProcess() {
//run process here
}
}

 The output is as follows:

    Done!
主站蜘蛛池模板: 阜新| 锦州市| 屯留县| 象山县| 自治县| 宝应县| 沙坪坝区| 禄丰县| 工布江达县| 清苑县| 江阴市| 仙游县| 金寨县| 上饶市| 阜城县| 乌苏市| 长沙县| 衡阳县| 固镇县| 碌曲县| 广安市| 衡水市| 增城市| 商都县| 永德县| 虹口区| 石渠县| 卢龙县| 洛宁县| 高陵县| 九龙城区| 洞头县| 安龙县| 镇坪县| 枣强县| 塘沽区| 浑源县| 新竹县| 托克托县| 黄浦区| 临城县|