public abstract class AsyncCompletableSubscriber extends java.lang.Object implements CompletableSubscriber, Subscription
Calling unsubscribe() and isUnsubscribed() is thread-safe and can happen at any time, even
before or during an active Completable.subscribe(CompletableSubscriber) call.
Override the onStart() method to execute custom logic on the very first successful onSubscribe call.
If one wants to remain consistent regarding isUnsubscribed() and being terminated,
the clear() method should be called from the implementing onError and onCompleted methods.
public final class MyCompletableSubscriber extends AsyncCompletableSubscriber {
@Override
public void onStart() {
System.out.println("Started!");
}
@Override
public void onCompleted() {
System.out.println("Completed!");
clear();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
clear();
}
}
| Constructor and Description |
|---|
AsyncCompletableSubscriber() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
clear()
Call to clear the upstream's subscription without unsubscribing it.
|
boolean |
isUnsubscribed()
Indicates whether this
Subscription is currently unsubscribed. |
protected void |
onStart()
Called before the first onSubscribe() call succeeds.
|
void |
onSubscribe(Subscription d)
Called once by the Completable to set a Subscription on this instance which
then can be used to cancel the subscription at any time.
|
void |
unsubscribe()
Stops the receipt of notifications on the
Subscriber that was registered when this Subscription
was received. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonCompleted, onErrorpublic final void onSubscribe(Subscription d)
CompletableSubscriberonSubscribe in interface CompletableSubscriberd - the Subscription instance to call dispose on for cancellation, not nullprotected void onStart()
public final boolean isUnsubscribed()
SubscriptionSubscription is currently unsubscribed.isUnsubscribed in interface Subscriptiontrue if this Subscription is currently unsubscribed, false otherwiseprotected final void clear()
public final void unsubscribe()
SubscriptionSubscriber that was registered when this Subscription
was received.
This allows deregistering an Subscriber before it has finished receiving all events (i.e. before
onCompleted is called).
unsubscribe in interface Subscription