- 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!
推薦閱讀
- OpenDaylight Cookbook
- JavaScript高效圖形編程
- Spring Cloud Alibaba微服務架構設計與開發實戰
- LabVIEW入門與實戰開發100例
- Java面向對象思想與程序設計
- Access 數據庫應用教程
- JavaScript從入門到精通(第3版)
- TypeScript項目開發實戰
- Unity 2D Game Development Cookbook
- SQL 經典實例
- Mastering Python Design Patterns
- scikit-learn Cookbook(Second Edition)
- Mastering OpenStack
- JavaWeb從入門到精通(視頻實戰版)
- 少兒編程輕松學(全2冊)