T- the value type received and emitted
public final class SingleSubject<T> extends Single<T> implements SingleObserver<T>
This subject does not have a public constructor by design; a new non-terminated instance of this
SingleSubject can be created via the
SingleSubject is conceptionally derived from the
Processor type in the Reactive Streams specification,
nulls are not allowed (Rule 2.13)
as parameters to
onError(Throwable). Such calls will result in a
NullPointerException being thrown and the subject's state is not changed.
SingleSubject is a
will move this
SingleSubject into its terminal state atomically.
All methods are thread safe. Calling
times has no effect. Calling
onError(Throwable) multiple times relays the
RxJavaPlugins.onError(Throwable) global error handler.
SingleSubject implements the
SingleObserver interface, calling
onSubscribe is not required (Rule 2.12)
if the subject is used as a standalone source. However, calling
SingleSubject reached its terminal state will result in the
Disposable being disposed immediately.
SingleSubject supports the standard state-peeking methods
hasObservers() as well as means to read any success item in a non-blocking
and thread-safe manner via
SingleSubject does not support clearing its cached
SingleSubjectdoes not operate by default on a particular
SingleObservers get notified on the thread where the terminating
onErrormethods were invoked.
onError(Throwable)is called, the
SingleSubjectenters into a terminal state and emits the same
Throwableinstance to the last set of
SingleObservers. During this emission, if one or more
SingleObservers dispose their respective
Throwableis delivered to the global error handler via
RxJavaPlugins.onError(Throwable)(multiple times if multiple
SingleObservers cancel at once). If there were no
SingleObservers subscribed to this
onError()was called, the global error handler is not invoked.
SingleSubject<Integer> subject1 = SingleSubject.create(); TestObserver<Integer> to1 = subject1.test(); // SingleSubjects are empty by default to1.assertEmpty(); subject1.onSuccess(1); // onSuccess is a terminal event with SingleSubjects // TestObserver converts onSuccess into onNext + onComplete to1.assertResult(1); TestObserver<Integer> to2 = subject1.test(); // late Observers receive the terminal signal (onSuccess) too to2.assertResult(1);
History: 2.0.5 - experimental
|Modifier and Type||Method and Description|
Creates a fresh SingleSubject.
Returns the terminal error if this SingleSubject has been terminated with an error, null otherwise.
Returns the success value if this SingleSubject was terminated with a success value.
Returns true if this SingleSubject has observers.
Returns true if this SingleSubject has been terminated with an error.
Returns true if this SingleSubject was terminated with a success value.
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
Implement this method in subclasses to handle the incoming
amb, ambArray, ambWith, as, blockingGet, cache, cast, compose, concat, concat, concat, concat, concat, concat, concat, concatArray, concatArrayEager, concatEager, concatEager, concatWith, contains, contains, create, defer, delay, delay, delay, delay, delaySubscription, delaySubscription, delaySubscription, delaySubscription, delaySubscription, delaySubscription, dematerialize, doAfterSuccess, doAfterTerminate, doFinally, doOnDispose, doOnError, doOnEvent, doOnSubscribe, doOnSuccess, doOnTerminate, equals, error, error, filter, flatMap, flatMapCompletable, flatMapMaybe, flatMapObservable, flatMapPublisher, flattenAsFlowable, flattenAsObservable, fromCallable, fromFuture, fromFuture, fromFuture, fromFuture, fromObservable, fromPublisher, hide, ignoreElement, just, lift, map, materialize, merge, merge, merge, merge, merge, merge, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeWith, never, observeOn, onErrorResumeNext, onErrorResumeNext, onErrorReturn, onErrorReturnItem, onTerminateDetach, repeat, repeat, repeatUntil, repeatWhen, retry, retry, retry, retry, retry, retryWhen, subscribe, subscribe, subscribe, subscribe, subscribe, subscribeOn, subscribeWith, takeUntil, takeUntil, takeUntil, test, test, timeout, timeout, timeout, timeout, timer, timer, to, toCompletable, toFlowable, toFuture, toMaybe, toObservable, unsafeCreate, unsubscribeOn, using, using, wrap, zip, zip, zip, zip, zip, zip, zip, zip, zip, zipArray, zipWith
@CheckReturnValue @NonNull public static <T> SingleSubject<T> create()
T- the value type received and emitted
public void onSubscribe(@NonNull Disposable d)
onSubscribe(Disposable)itself) and asynchronous manner.
Singlehas finished sending push-based notifications.
Singlehas experienced an error condition.
protected void subscribeActual(@NonNull SingleObserver<? super T> observer)
There is no need to call any of the plugin hooks on the current
Single instance or
SingleObserver; all hooks and basic safeguards have been
Single.subscribe(SingleObserver) before this method gets called.
public boolean hasValue()
public boolean hasThrowable()
public boolean hasObservers()