public abstract class DisposableCompletableObserver extends Object implements CompletableObserver, Disposable
CompletableObserver that allows asynchronous cancellation by implementing Disposable.
All pre-implemented final methods are thread-safe.
Like all other consumers, DisposableCompletableObserver can be subscribed only once.
Any subsequent attempt to subscribe it to a new source will yield an
IllegalStateException with message "It is not allowed to subscribe with a(n) <class name> multiple times.".
Implementation of onStart(), CompletableObserver.onError(Throwable) and
CompletableObserver.onComplete() are not allowed to throw any unchecked exceptions.
Example
Disposable d =
Completable.complete().delay(1, TimeUnit.SECONDS)
.subscribeWith(new DisposableMaybeObserver<Integer>() {
@Override public void onStart() {
System.out.println("Start!");
}
@Override public void onError(Throwable t) {
t.printStackTrace();
}
@Override public void onComplete() {
System.out.println("Done!");
}
});
// ...
d.dispose();
| Constructor and Description |
|---|
DisposableCompletableObserver() |
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Dispose the resource, the operation should be idempotent.
|
boolean |
isDisposed()
Returns true if this resource has been disposed.
|
protected void |
onStart()
Called once the single upstream
Disposable is set via onSubscribe(Disposable). |
void |
onSubscribe(@NonNull Disposable d)
Called once by the
Completable to set a Disposable on this instance which
then can be used to cancel the subscription at any time. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonComplete, onErrordisposed, empty, fromAction, fromAutoCloseable, fromFuture, fromFuture, fromRunnable, fromSubscription, toAutoCloseablepublic final void onSubscribe(@NonNull @NonNull Disposable d)
CompletableObserverCompletable to set a Disposable on this instance which
then can be used to cancel the subscription at any time.onSubscribe in interface CompletableObserverd - the Disposable instance to call dispose on for cancellation, not nullprotected void onStart()
Disposable is set via onSubscribe(Disposable).public final boolean isDisposed()
DisposableisDisposed in interface Disposablepublic final void dispose()
Disposabledispose in interface Disposable