- 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!
推薦閱讀
- Instant Testing with CasperJS
- 碼上行動:零基礎學會Python編程(ChatGPT版)
- Java軟件開發基礎
- 鋒利的SQL(第2版)
- OpenStack Orchestration
- Julia高性能科學計算(第2版)
- C#程序設計(項目教學版)
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- Python自然語言理解:自然語言理解系統開發與應用實戰
- .NET 4.0面向對象編程漫談:應用篇
- Angular Design Patterns
- Maven for Eclipse
- Java服務端研發知識圖譜
- Azure for Architects
- Slick2D Game Development