- 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!
推薦閱讀
- 軟件安全技術
- UI設計基礎培訓教程
- Python程序設計教程(第2版)
- CentOS 7 Linux Server Cookbook(Second Edition)
- Android 9 Development Cookbook(Third Edition)
- C語言程序設計案例式教程
- 軟件架構:Python語言實現
- 深入淺出Serverless:技術原理與應用實踐
- Node.js Design Patterns
- jQuery Mobile移動應用開發實戰(第3版)
- Python算法詳解
- Programming with CodeIgniterMVC
- Couchbase Essentials
- RESTful Web Clients:基于超媒體的可復用客戶端
- 例解Python:Python編程快速入門踐行指南