- 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!
推薦閱讀
- UML和模式應用(原書第3版)
- Android應用程序開發與典型案例
- Microsoft Dynamics 365 Extensions Cookbook
- C語言程序設計基礎與實驗指導
- Java FX應用開發教程
- Production Ready OpenStack:Recipes for Successful Environments
- Python 3破冰人工智能:從入門到實戰
- PHP+Ajax+jQuery網站開發項目式教程
- Internet of Things with ESP8266
- PrimeFaces Blueprints
- PHP與MySQL權威指南
- Vue.js光速入門及企業項目開發實戰
- Arduino電子設計實戰指南:零基礎篇
- Java算法從菜鳥到達人
- Web 2.0策略指南