Interface SingleObserver<T>
-
- Type Parameters:
T
- the type of item the SingleObserver expects to observe
- All Known Implementing Classes:
BiConsumerSingleObserver
,BlockingDisposableMultiObserver
,BlockingMultiObserver
,CompletableFromSingle.CompletableFromSingleObserver
,CompletionStageConsumer
,ConsumerSingleObserver
,DisposableAutoReleaseMultiObserver
,DisposableSingleObserver
,EmptyComponent
,FlowableConcatMapSingle.ConcatMapSingleSubscriber.ConcatMapSingleObserver
,FlowableConcatWithSingle.ConcatWithSubscriber
,FlowableFlatMapSingle.FlatMapSingleSubscriber.InnerObserver
,FlowableMergeWithSingle.MergeWithObserver.OtherObserver
,FlowableSwitchMapSingle.SwitchMapSingleSubscriber.SwitchMapSingleObserver
,FutureMultiObserver
,MaterializeSingleObserver
,MaybeFilterSingle.FilterMaybeObserver
,MaybeFlatMapSingle.FlatMapSingleObserver
,MaybeFlattenStreamAsFlowable.FlattenStreamMultiObserver
,MaybeFlattenStreamAsObservable.FlattenStreamMultiObserver
,MaybeFromSingle.FromSingleObserver
,MaybeOnErrorComplete.OnErrorCompleteMultiObserver
,MaybeSwitchIfEmptySingle.SwitchIfEmptyMaybeObserver.OtherSingleObserver
,ObservableConcatMapSingle.ConcatMapSingleMainObserver.ConcatMapSingleObserver
,ObservableConcatWithSingle.ConcatWithObserver
,ObservableFlatMapSingle.FlatMapSingleObserver.InnerObserver
,ObservableMergeWithSingle.MergeWithObserver.OtherObserver
,ObservableSwitchMapSingle.SwitchMapSingleMainObserver.SwitchMapSingleObserver
,ResourceSingleObserver
,ResumeSingleObserver
,SafeSingleObserver
,SingleAmb.AmbSingleObserver
,SingleCache
,SingleContains.ContainsSingleObserver
,SingleDelay.Delay
,SingleDelayWithSingle.OtherObserver
,SingleDematerialize.DematerializeObserver
,SingleDetach.DetachSingleObserver
,SingleDoAfterSuccess.DoAfterObserver
,SingleDoAfterTerminate.DoAfterTerminateObserver
,SingleDoFinally.DoFinallyObserver
,SingleDoOnDispose.DoOnDisposeObserver
,SingleDoOnError.DoOnError
,SingleDoOnEvent.DoOnEvent
,SingleDoOnLifecycle.SingleLifecycleObserver
,SingleDoOnSubscribe.DoOnSubscribeSingleObserver
,SingleDoOnSuccess.DoOnSuccess
,SingleDoOnTerminate.DoOnTerminate
,SingleEquals.InnerObserver
,SingleFlatMap.SingleFlatMapCallback
,SingleFlatMap.SingleFlatMapCallback.FlatMapSingleObserver
,SingleFlatMapBiSelector.FlatMapBiMainObserver
,SingleFlatMapBiSelector.FlatMapBiMainObserver.InnerObserver
,SingleFlatMapCompletable.FlatMapCompletableObserver
,SingleFlatMapIterableFlowable.FlatMapIterableObserver
,SingleFlatMapIterableObservable.FlatMapIterableObserver
,SingleFlatMapMaybe.FlatMapSingleObserver
,SingleFlatMapNotification.FlatMapSingleObserver
,SingleFlatMapNotification.FlatMapSingleObserver.InnerObserver
,SingleFlatMapObservable.FlatMapObserver
,SingleFlatMapPublisher.SingleFlatMapPublisherObserver
,SingleHide.HideSingleObserver
,SingleMap.MapSingleObserver
,SingleMapOptional.MapOptionalSingleObserver
,SingleObserveOn.ObserveOnSingleObserver
,SingleOnErrorReturn.OnErrorReturn
,SingleResumeNext.ResumeMainSingleObserver
,SingleSubject
,SingleSubscribeOn.SubscribeOnObserver
,SingleTakeUntil.TakeUntilMainObserver
,SingleTimeInterval.TimeIntervalSingleObserver
,SingleTimeout.TimeoutMainObserver
,SingleTimeout.TimeoutMainObserver.TimeoutFallbackObserver
,SingleToFlowable.SingleToFlowableObserver
,SingleToObservable.SingleToObservableObserver
,SingleUnsubscribeOn.UnsubscribeOnSingleObserver
,SingleUsing.UsingSingleObserver
,SingleZipArray.ZipSingleObserver
,TestObserver
public interface SingleObserver<@NonNull T>
Provides a mechanism for receiving push-based notification of a single value or an error.When a
SingleObserver
is subscribed to aSingleSource
through theSingleSource.subscribe(SingleObserver)
method, theSingleSource
callsonSubscribe(Disposable)
with aDisposable
that allows disposing the sequence at any time. A well-behavedSingleSource
will call aSingleObserver
'sonSuccess(Object)
method exactly once or theSingleObserver
'sonError(java.lang.Throwable)
method exactly once as they are considered mutually exclusive terminal signals.Calling the
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)?
Subscribing a
SingleObserver
to multipleSingleSource
s is not recommended. If such reuse happens, it is the duty of theSingleObserver
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)
oronError(Throwable)
with anull
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 preventsnull
s 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:
- ReactiveX documentation: Observable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
onError(@NonNull java.lang.Throwable e)
Notifies theSingleObserver
that theSingle
has experienced an error condition.void
onSubscribe(@NonNull Disposable d)
Provides theSingleObserver
with the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)
itself) and asynchronous manner.void
onSuccess(@NonNull T t)
Notifies theSingleObserver
with a single item and that theSingle
has finished sending push-based notifications.
-
-
-
Method Detail
-
onSubscribe
void onSubscribe(@NonNull @NonNull Disposable d)
Provides theSingleObserver
with the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)
itself) and asynchronous manner.- Parameters:
d
- the Disposable instance whoseDisposable.dispose()
can be called anytime to cancel the connection- Since:
- 2.0
-
onSuccess
void onSuccess(@NonNull @NonNull T t)
Notifies theSingleObserver
with a single item and that theSingle
has finished sending push-based notifications.The
Single
will not call this method if it callsonError(java.lang.Throwable)
.- Parameters:
t
- the item emitted by theSingle
-
onError
void onError(@NonNull @NonNull java.lang.Throwable e)
Notifies theSingleObserver
that theSingle
has experienced an error condition.If the
Single
calls this method, it will not thereafter callonSuccess(T)
.- Parameters:
e
- the exception encountered by theSingle
-
-