Interface MaybeObserver<T>
- Type Parameters:
T- the type of item the MaybeObserver expects to observe
- All Known Implementing Classes:
DisposableMaybeObserver, MaybeSubject, ResourceMaybeObserver, TestObserver
When a MaybeObserver is subscribed to a MaybeSource through the MaybeSource.subscribe(MaybeObserver) method,
the MaybeSource calls onSubscribe(Disposable) with a Disposable that allows
disposing the sequence at any time. A well-behaved
MaybeSource will call a MaybeObserver's onSuccess(Object), onError(Throwable)
or onComplete() method exactly once as they are considered mutually exclusive terminal signals.
Calling the MaybeObserver's method must happen in a serialized fashion, that is, they must not
be invoked concurrently by multiple threads in an overlapping fashion and the invocation pattern must
adhere to the following protocol:
onSubscribe (onSuccess | onError | onComplete)?
Note that unlike with the Observable protocol, onComplete() is not called after the success item has been
signalled via onSuccess(Object).
Subscribing a MaybeObserver to multiple MaybeSources is not recommended. If such reuse
happens, it is the duty of the MaybeObserver implementation to be ready to receive multiple calls to
its methods and ensure proper concurrent behavior of its business logic.
Calling onSubscribe(Disposable), onSuccess(Object) or onError(Throwable) with a
null argument is forbidden.
The implementations of the onXXX methods should avoid throwing runtime exceptions other than the following cases:
- If the argument is
null, the methods can throw aNullPointerException. Note though that RxJava preventsnulls to enter into the flow and thus there is generally no need to check for nulls in flows assembled from standard sources and intermediate operators. - If there is a fatal error (such as
VirtualMachineError).
- Since:
- 2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidCalled once the deferred computation completes normally.voidNotifies theMaybeObserverthat theMaybehas experienced an error condition.voidProvides theMaybeObserverwith the means of cancelling (disposing) the connection (channel) with theMaybein both synchronous (from withinonSubscribe(Disposable)itself) and asynchronous manner.voidNotifies theMaybeObserverwith one item and that theMaybehas finished sending push-based notifications.
-
Method Details
-
onSubscribe
Provides theMaybeObserverwith the means of cancelling (disposing) the connection (channel) with theMaybein both synchronous (from withinonSubscribe(Disposable)itself) and asynchronous manner.- Parameters:
d- theDisposableinstance whoseDisposable.dispose()can be called anytime to cancel the connection
-
onSuccess
Notifies theMaybeObserverwith one item and that theMaybehas finished sending push-based notifications.The
Maybewill not call this method if it callsonError(Throwable).- Parameters:
t- the item emitted by theMaybe
-
onError
Notifies theMaybeObserverthat theMaybehas experienced an error condition.If the
Maybecalls this method, it will not thereafter callonSuccess(T).- Parameters:
e- the exception encountered by theMaybe
-
onComplete
void onComplete()Called once the deferred computation completes normally.
-