Package rx.internal.operators
Class DeferredScalarSubscriber<T,R>
java.lang.Object
rx.Subscriber<T>
rx.internal.operators.DeferredScalarSubscriber<T,R>
- Type Parameters:
T- the source value typeR- the result value type
- All Implemented Interfaces:
Observer<T>,Subscription
- Direct Known Subclasses:
OnSubscribeCollect.CollectSubscriber,OnSubscribeReduceSeed.ReduceSeedSubscriber,OnSubscribeTakeLastOne.TakeLastOneSubscriber
Base class for Subscribers that consume the entire upstream and signal
zero or one element (or an error) in a backpressure honoring fashion.
Store any temporary value in value and indicate there is
a value available when completing by setting hasValue.
invalid input: '<'p.
Use subscribeTo(Observable) to properly setup the link between this and the downstream
subscriber.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classRedirects the downstream request amount bach to the DeferredScalarSubscriber. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Subscriber<? super R> The downstream subscriber.(package private) static final intValue will be emitted.(package private) static final intRequest came first.protected booleanIndicates there is a value available in value.(package private) static final intValue came first.(package private) static final intInitial state.(package private) final AtomicIntegerThe state, see the constants below.protected RThe holder of the single value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidcomplete()Signals onCompleted() to the downstream subscriber.protected final voidAtomically switches to the terminal state and emits the value if there is a request for it or stores it for retrieval bydownstreamRequest(long).(package private) final voiddownstreamRequest(long n) voidNotifies the Observer that theObservablehas finished sending push-based notifications.voidNotifies the Observer that theObservablehas experienced an error condition.final voidIf other subscriber is set (by calling constructorSubscriber(Subscriber)orSubscriber(Subscriber, boolean)) then this method callssetProduceron the other subscriber.(package private) final voidfinal voidsubscribeTo(Observable<? extends T> source) Links up with the downstream Subscriber (cancellation, backpressure) and subscribes to the source Observable.Methods inherited from class rx.Subscriber
add, isUnsubscribed, onStart, request, unsubscribe
-
Field Details
-
actual
The downstream subscriber. -
hasValue
protected boolean hasValueIndicates there is a value available in value. -
value
The holder of the single value. -
state
The state, see the constants below. -
NO_REQUEST_NO_VALUE
static final int NO_REQUEST_NO_VALUEInitial state.- See Also:
-
HAS_REQUEST_NO_VALUE
static final int HAS_REQUEST_NO_VALUERequest came first.- See Also:
-
NO_REQUEST_HAS_VALUE
static final int NO_REQUEST_HAS_VALUEValue came first.- See Also:
-
HAS_REQUEST_HAS_VALUE
static final int HAS_REQUEST_HAS_VALUEValue will be emitted.- See Also:
-
-
Constructor Details
-
DeferredScalarSubscriber
-
-
Method Details
-
onError
Description copied from interface:ObserverNotifies the Observer that theObservablehas experienced an error condition.If the
Observablecalls this method, it will not thereafter callObserver.onNext(T)orObserver.onCompleted().- Parameters:
ex- the exception encountered by the Observable
-
onCompleted
public void onCompleted()Description copied from interface:ObserverNotifies the Observer that theObservablehas finished sending push-based notifications.The
Observablewill not call this method if it callsObserver.onError(java.lang.Throwable). -
complete
protected final void complete()Signals onCompleted() to the downstream subscriber. -
complete
Atomically switches to the terminal state and emits the value if there is a request for it or stores it for retrieval bydownstreamRequest(long).- Parameters:
value- the value to complete with
-
downstreamRequest
final void downstreamRequest(long n) -
setProducer
Description copied from class:SubscriberIf other subscriber is set (by calling constructorSubscriber(Subscriber)orSubscriber(Subscriber, boolean)) then this method callssetProduceron the other subscriber. If the other subscriber is not set and no requests have been made to this subscriber thenp.request(Long.MAX_VALUE)is called. If the other subscriber is not set and some requests have been made to this subscriber thenp.request(n)is called where n is the accumulated requests to this subscriber.- Overrides:
setProducerin classSubscriber<T>- Parameters:
p- producer to be used by this subscriber or the other subscriber (or recursively its other subscriber) to make requests from
-
subscribeTo
Links up with the downstream Subscriber (cancellation, backpressure) and subscribes to the source Observable.- Parameters:
source- the source Observable
-
setupDownstream
final void setupDownstream()
-