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

  • Learning RxJava
  • Thomas Nield
  • 122字
  • 2021-07-02 22:22:55

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!
主站蜘蛛池模板: 临城县| 武威市| 弥渡县| 大港区| 永靖县| 嘉善县| 文安县| 丹巴县| 孟连| 仪陇县| 闸北区| 章丘市| 炉霍县| 瓮安县| 麻城市| 西和县| 彰化市| 南汇区| 苏尼特左旗| 资源县| 丘北县| 平安县| 塔城市| 印江| 黄龙县| 贡觉县| 泰州市| 友谊县| 枣强县| 会理县| 澄迈县| 板桥市| 巴中市| 班戈县| 临沧市| 乌兰县| 荔浦县| 遂川县| 衡阳县| 巴塘县| 太仆寺旗|