T - the value type to emitpublic interfaceMaybeEmitter<T>MaybeObserver that allows associating a resource with it.All methods are safe to call from multiple threads, but note that there is no guarantee whose terminal event will win and get delivered to the downstream.
CallingonSuccess(Object) oronComplete() multiple times has no effect. CallingonError(Throwable) multiple times or after the other two will route the exception into the global error handler viaRxJavaPlugins.onError(Throwable).
The emitter allows the registration of a single resource, in the form of aDisposable orCancellable viasetDisposable(Disposable) orsetCancellable(Cancellable) respectively. The emitter implementations will dispose/cancel this instance when the downstream cancels the flow or after the event generator logic callsonSuccess(Object),onError(Throwable),onComplete() or whentryOnError(Throwable) succeeds.
Only oneDisposable orCancellable object can be associated with the emitter at a time. Calling eitherset method will dispose/cancel any previous object. If there is a need for handling multiple resources, one can create aCompositeDisposable and associate that with the emitter instead.
TheCancellable is logically equivalent toDisposable but allows using cleanup logic that can throw a checked exception (such as manyclose() methods on Java IO components). Since the release of resources happens after the terminal events have been delivered or the sequence gets cancelled, exceptions throw withinCancellable are routed to the global error handler viaRxJavaPlugins.onError(Throwable).
| Modifier and Type | Method and Description |
|---|---|
boolean | isDisposed()Returns true if the downstream disposed the sequence or the emitter was terminated via onSuccess(Object),onError(Throwable),onComplete() or a successfultryOnError(Throwable). |
void | onComplete()Signal the completion. |
void | onError(Throwable t)Signal an exception. |
void | onSuccess(T t)Signal a success value. |
void | setCancellable(Cancellable c)Sets a Cancellable on this emitter; any previous Disposable orCancellable will be disposed/cancelled. |
void | setDisposable(Disposable d)Sets a Disposable on this emitter; any previous Disposable orCancellable will be disposed/cancelled. |
boolean | tryOnError(Throwable t)Attempts to emit the specified Throwable error if the downstream hasn't cancelled the sequence or is otherwise terminated, returning false if the emission is not allowed to happen due to lifecycle restrictions. |
void onComplete()
void setDisposable(@NullableDisposable d)
Disposable orCancellable will be disposed/cancelled.d - the disposable, null is allowedvoid setCancellable(@NullableCancellable c)
Disposable orCancellable will be disposed/cancelled.c - the cancellable resource, null is allowedboolean isDisposed()
onSuccess(Object),onError(Throwable),onComplete() or a successfultryOnError(Throwable).This method is thread-safe.
boolean tryOnError(@NonNullThrowable t)
Throwable error if the downstream hasn't cancelled the sequence or is otherwise terminated, returning false if the emission is not allowed to happen due to lifecycle restrictions. UnlikeonError(Throwable), theRxJavaPlugins.onError is not called if the error could not be delivered.
History: 2.1.1 - experimental
t - the throwable error to signal if possible