When a consumer subscribes, the given
io.reactivex.function.Action is invoked and the consumer completes or receives the exception the
Runnable runnable = () -> System.out.println("Hello World!"); Completable completable = Completable.fromRunnable(runnable); completable.subscribe(() -> System.out.println("Done"), error -> error.printStackTrace());
Note: the difference between
fromRunnableis that the
Actioninterface allows throwing a checked exception while the
The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.