public abstract class DisposableCompletableObserver extends java.lang.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 "Disposable already set!"
.
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.
|
void |
onSubscribe(Disposable s)
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, wait
onComplete, onError
public final void onSubscribe(Disposable s)
CompletableObserver
onSubscribe
in interface CompletableObserver
s
- the Disposable instance to call dispose on for cancellation, not nullprotected void onStart()
public final boolean isDisposed()
Disposable
isDisposed
in interface Disposable
public final void dispose()
Disposable
dispose
in interface Disposable