T- the type of item the SingleObserver expects to observe
public interface SingleObserver<T>
SingleObserver is subscribed to a
SingleSource through the
onSubscribe(Disposable) with a
Disposable that allows
disposing the sequence at any time. A well-behaved
SingleSource will call a
onSuccess(Object) method exactly once or the
onError(java.lang.Throwable) method exactly once as they are considered mutually exclusive terminal signals.
SingleObserver'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)?
SingleObserver to multiple
SingleSources is not recommended. If such reuse
happens, it is the duty of the
SingleObserver implementation to be ready to receive multiple calls to
its methods and ensure proper concurrent behavior of its business logic.
onError(Throwable) with a
null argument is forbidden.
The implementations of the
onXXX methods should avoid throwing runtime exceptions other than the following cases:
null, the methods can throw a
NullPointerException. Note though that RxJava prevents
nulls 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.
|Modifier and Type||Method and Description|
Notifies the SingleObserver that the
Provides the SingleObserver with the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from within
Notifies the SingleObserver with a single item and that the
void onSubscribe(@NonNull Disposable d)
onSubscribe(Disposable)itself) and asynchronous manner.
d- the Disposable instance whose
Disposable.dispose()can be called anytime to cancel the connection
void onSuccess(@NonNull T t)
Singlehas finished sending push-based notifications.
Single will not call this method if it calls
t- the item emitted by the Single
void onError(@NonNull Throwable e)
Singlehas experienced an error condition.
Single calls this method, it will not thereafter call
e- the exception encountered by the Single