Package rx.observers
Class AsyncCompletableSubscriber
- java.lang.Object
-
- rx.observers.AsyncCompletableSubscriber
-
- All Implemented Interfaces:
Completable.CompletableSubscriber
,Subscription
@Experimental public abstract class AsyncCompletableSubscriber extends java.lang.Object implements Completable.CompletableSubscriber, Subscription
An abstract base class for CompletableSubscriber implementations that want to expose an unsubscription capability.Calling
unsubscribe()
andisUnsubscribed()
is threadsafe and can happen at any time, even before or during an activeCompletable.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, theclear()
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(); } }
- Since:
- (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AsyncCompletableSubscriber.Unsubscribed
-
Field Summary
Fields Modifier and Type Field Description (package private) static AsyncCompletableSubscriber.Unsubscribed
UNSUBSCRIBED
Indicates the unsubscribed state.private java.util.concurrent.atomic.AtomicReference<Subscription>
upstream
Holds onto a deferred subscription and allows asynchronous cancellation before the call to onSubscribe() by the upstream.
-
Constructor Summary
Constructors Constructor Description AsyncCompletableSubscriber()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
clear()
Call to clear the upstream's subscription without unsubscribing it.boolean
isUnsubscribed()
Indicates whether thisSubscription
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 theSubscriber
that was registered when this Subscription was received.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface rx.Completable.CompletableSubscriber
onCompleted, onError
-
-
-
-
Field Detail
-
UNSUBSCRIBED
static final AsyncCompletableSubscriber.Unsubscribed UNSUBSCRIBED
Indicates the unsubscribed state.
-
upstream
private final java.util.concurrent.atomic.AtomicReference<Subscription> upstream
Holds onto a deferred subscription and allows asynchronous cancellation before the call to onSubscribe() by the upstream.
-
-
Method Detail
-
onSubscribe
public final void onSubscribe(Subscription d)
Description copied from interface:Completable.CompletableSubscriber
Called once by the Completable to set a Subscription on this instance which then can be used to cancel the subscription at any time.- Specified by:
onSubscribe
in interfaceCompletable.CompletableSubscriber
- Parameters:
d
- the Subscription instance to call dispose on for cancellation, not null
-
onStart
protected void onStart()
Called before the first onSubscribe() call succeeds.
-
isUnsubscribed
public final boolean isUnsubscribed()
Description copied from interface:Subscription
Indicates whether thisSubscription
is currently unsubscribed.- Specified by:
isUnsubscribed
in interfaceSubscription
- Returns:
true
if thisSubscription
is currently unsubscribed,false
otherwise
-
clear
protected final void clear()
Call to clear the upstream's subscription without unsubscribing it.
-
unsubscribe
public final void unsubscribe()
Description copied from interface:Subscription
Stops the receipt of notifications on theSubscriber
that was registered when this Subscription was received.This allows unregistering an
Subscriber
before it has finished receiving all events (i.e. before onCompleted is called).- Specified by:
unsubscribe
in interfaceSubscription
-
-