- 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!
推薦閱讀
- 多媒體CAI課件設(shè)計(jì)與制作導(dǎo)論(第二版)
- 新一代通用視頻編碼H.266/VVC:原理、標(biāo)準(zhǔn)與實(shí)現(xiàn)
- 看透JavaScript:原理、方法與實(shí)踐
- MySQL 8 DBA基礎(chǔ)教程
- 微服務(wù)設(shè)計(jì)原理與架構(gòu)
- Java開發(fā)入行真功夫
- jQuery開發(fā)基礎(chǔ)教程
- Learning Salesforce Einstein
- Mastering Android Game Development
- Machine Learning in Java
- GameMaker Essentials
- Effective C++:改善程序與設(shè)計(jì)的55個(gè)具體做法(第三版)中文版(雙色)
- 現(xiàn)代C++語言核心特性解析
- Backbone.js Patterns and Best Practices
- Swift 2 Blueprints