T
- the source value typeR
- the result value typepublic abstract class DeferredScalarSubscriber<T,R> extends Subscriber<T>
Store any temporary value in value
and indicate there is
a value available when completing by setting hasValue
.
subscribeTo(Observable)
to properly setup the link between this and the downstream
subscriber.Modifier and Type | Field and Description |
---|---|
protected Subscriber<? super R> |
actual
The downstream subscriber.
|
protected boolean |
hasValue
Indicates there is a value available in value.
|
protected R |
value
The holder of the single value.
|
Constructor and Description |
---|
DeferredScalarSubscriber(Subscriber<? super R> actual) |
Modifier and Type | Method and Description |
---|---|
protected void |
complete()
Signals onCompleted() to the downstream subscriber.
|
protected void |
complete(R value)
Atomically switches to the terminal state and emits the value if
there is a request for it or stores it for retrieval by
downstreamRequest(long) . |
void |
onCompleted()
Notifies the Observer that the
Observable has finished sending push-based notifications. |
void |
onError(Throwable ex)
Notifies the Observer that the
Observable has experienced an error condition. |
void |
setProducer(Producer p)
If other subscriber is set (by calling constructor
Subscriber.Subscriber(Subscriber) or
Subscriber.Subscriber(Subscriber, boolean) ) then this method calls
setProducer on the other subscriber. |
void |
subscribeTo(Observable<? extends T> source)
Links up with the downstream Subscriber (cancellation, backpressure) and
subscribes to the source Observable.
|
add, isUnsubscribed, onStart, request, unsubscribe
protected final Subscriber<? super R> actual
protected boolean hasValue
protected R value
public DeferredScalarSubscriber(Subscriber<? super R> actual)
public void onError(Throwable ex)
Observer
Observable
has experienced an error condition.
If the Observable
calls this method, it will not thereafter call Observer.onNext(T)
or
Observer.onCompleted()
.
ex
- the exception encountered by the Observablepublic void onCompleted()
Observer
Observable
has finished sending push-based notifications.
The Observable
will not call this method if it calls Observer.onError(java.lang.Throwable)
.
protected final void complete()
protected final void complete(R value)
downstreamRequest(long)
.value
- the value to complete withpublic final void setProducer(Producer p)
Subscriber
Subscriber.Subscriber(Subscriber)
or
Subscriber.Subscriber(Subscriber, boolean)
) then this method calls
setProducer
on the other subscriber. If the other subscriber
is not set and no requests have been made to this subscriber then
p.request(Long.MAX_VALUE)
is called. If the other subscriber
is not set and some requests have been made to this subscriber then
p.request(n)
is called where n is the accumulated requests
to this subscriber.setProducer
in class Subscriber<T>
p
- producer to be used by this subscriber or the other subscriber
(or recursively its other subscriber) to make requests frompublic final void subscribeTo(Observable<? extends T> source)
source
- the source ObservableCopyright © 2017. All rights reserved.