T - the type of item expected by the Subscriberpublic class SafeSubscriber<T> extends Subscriber<T>
Observer that ensures compliance with the Rx contract.
The following is taken from the Rx Design Guidelines document:
Messages sent to instances of the
IObserverinterface follow the following grammar:
OnNext* (OnCompleted | OnError)?This grammar allows observable sequences to send any amount (0 or more) of
OnNextmessages to the subscribed observer instance, optionally followed by a single success (OnCompleted) or failure (OnError) message.The single message indicating that an observable sequence has finished ensures that consumers of the observable sequence can deterministically establish that it is safe to perform cleanup operations.
A single failure further ensures that abort semantics can be maintained for operators that work on multiple observable sequences (see paragraph 6.6).
This wrapper does the following:
onError or onCompleted.onCompleted or onError is performed, no further calls can be executedunsubscribe is called, calls completed and forbids any further onNext calls.onError or onComplete occur, unsubscribes from the Observable (if executing asynchronously). SafeSubscriber will not synchronize onNext execution. Use SerializedSubscriber to do
that.
| Constructor and Description |
|---|
SafeSubscriber(Subscriber<? super T> actual) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_onError(java.lang.Throwable e)
The logic for
onError without the isFinished check so it can be called from within onCompleted. |
Subscriber<? super T> |
getActual()
Returns the
Subscriber underlying this SafeSubscriber. |
void |
onCompleted()
Notifies the Observer that the
Observable has finished sending push-based notifications. |
void |
onError(java.lang.Throwable e)
Notifies the Observer that the
Observable has experienced an error condition. |
void |
onNext(T args)
Provides the Observer with a new item to observe.
|
add, isUnsubscribed, onStart, request, setProducer, unsubscribepublic SafeSubscriber(Subscriber<? super T> actual)
public void onCompleted()
ObserverObservable has finished sending push-based notifications.
The Observable will not call this method if it calls Observer.onError(java.lang.Throwable).
public void onError(java.lang.Throwable e)
ObserverObservable has experienced an error condition.
If the Observable calls this method, it will not thereafter call Observer.onNext(T) or
Observer.onCompleted().
e - the exception encountered by the Observablepublic void onNext(T args)
Observer
The Observable may call this closure 0 or more times.
The Observable will not call this closure again after it calls either Observer.onCompleted() or
Observer.onError(java.lang.Throwable).
args - the item emitted by the Observableprotected void _onError(java.lang.Throwable e)
onError without the isFinished check so it can be called from within onCompleted.public Subscriber<? super T> getActual()
Subscriber underlying this SafeSubscriber.Subscriber that was used to create this SafeSubscriber