Class SingleSubject<T>
- Type Parameters:
T- the value type received and emitted
- All Implemented Interfaces:
SingleObserver<T>, SingleSource<T>
This subject does not have a public constructor by design; a new non-terminated instance of this
SingleSubject can be created via the create() method.
Since the SingleSubject is conceptionally derived from the Processor type in the Reactive Streams specification,
nulls are not allowed (Rule 2.13)
as parameters to onSuccess(Object) and onError(Throwable). Such calls will result in a
NullPointerException being thrown and the subject's state is not changed.
Since a SingleSubject is a Single, calling onSuccess or onError
will move this SingleSubject into its terminal state atomically.
All methods are thread safe. Calling onSuccess(Object) multiple
times has no effect. Calling onError(Throwable) multiple times relays the Throwable to
the RxJavaPlugins.onError(Throwable) global error handler.
Even though SingleSubject implements the SingleObserver interface, calling
onSubscribe is not required (Rule 2.12)
if the subject is used as a standalone source. However, calling onSubscribe
after the SingleSubject reached its terminal state will result in the
given Disposable being disposed immediately.
This SingleSubject supports the standard state-peeking methods hasThrowable(),
getThrowable() and hasObservers() as well as means to read any success item in a non-blocking
and thread-safe manner via hasValue() and getValue().
The SingleSubject does not support clearing its cached onSuccess value.
- Scheduler:
SingleSubjectdoes not operate by default on a particularSchedulerand theSingleObservers get notified on the thread where the terminatingonSuccessoronErrormethods were invoked.- Error handling:
- When the
onError(Throwable)is called, theSingleSubjectenters into a terminal state and emits the sameThrowableinstance to the last set ofSingleObservers. During this emission, if one or moreSingleObservers dispose their respectiveDisposables, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)(multiple times if multipleSingleObservers cancel at once). If there were noSingleObservers subscribed to thisSingleSubjectwhen theonError()was called, the global error handler is not invoked.
Example usage:
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
- Since:
- 2.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NonNull SingleSubject<T> create()Creates a fresh SingleSubject.Returns the terminal error if this SingleSubject has been terminated with an error, null otherwise.getValue()Returns the success value if this SingleSubject was terminated with a success value.booleanReturns true if this SingleSubject has observers.booleanReturns true if this SingleSubject has been terminated with an error.booleanhasValue()Returns true if this SingleSubject was terminated with a success value.voidNotifies theSingleObserverthat theSinglehas experienced an error condition.voidProvides theSingleObserverwith the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)itself) and asynchronous manner.voidNotifies theSingleObserverwith a single item and that theSinglehas finished sending push-based notifications.protected voidsubscribeActual(@NonNull SingleObserver<? super T> observer) Implement this method in subclasses to handle the incomingSingleObservers.Methods inherited from class Single
amb, ambArray, ambWith, blockingGet, blockingSubscribe, blockingSubscribe, blockingSubscribe, blockingSubscribe, cache, cast, compose, concat, concat, concat, concat, concat, concat, concat, concatArray, concatArrayDelayError, concatArrayEager, concatArrayEagerDelayError, concatDelayError, concatDelayError, concatDelayError, concatEager, concatEager, concatEager, concatEager, concatEagerDelayError, concatEagerDelayError, concatEagerDelayError, concatEagerDelayError, concatMap, concatMapCompletable, concatMapMaybe, concatWith, contains, contains, create, defer, delay, delay, delay, delay, delaySubscription, delaySubscription, delaySubscription, delaySubscription, delaySubscription, delaySubscription, dematerialize, doAfterSuccess, doAfterTerminate, doFinally, doOnDispose, doOnError, doOnEvent, doOnLifecycle, doOnSubscribe, doOnSuccess, doOnTerminate, error, error, filter, flatMap, flatMap, flatMap, flatMapCompletable, flatMapMaybe, flatMapObservable, flatMapPublisher, flattenAsFlowable, flattenAsObservable, flattenStreamAsFlowable, flattenStreamAsObservable, fromCallable, fromCompletionStage, fromFuture, fromFuture, fromMaybe, fromMaybe, fromObservable, fromPublisher, fromSupplier, hide, ignoreElement, just, lift, map, mapOptional, materialize, merge, merge, merge, merge, merge, merge, mergeArray, mergeArrayDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeDelayError, mergeWith, never, observeOn, ofType, onErrorComplete, onErrorComplete, onErrorResumeNext, onErrorResumeWith, onErrorReturn, onErrorReturnItem, onTerminateDetach, repeat, repeat, repeatUntil, repeatWhen, retry, retry, retry, retry, retry, retryUntil, retryWhen, safeSubscribe, sequenceEqual, startWith, startWith, startWith, startWith, startWith, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, subscribeOn, subscribeWith, switchOnNext, switchOnNextDelayError, takeUntil, takeUntil, takeUntil, test, test, timeInterval, timeInterval, timeInterval, timeInterval, timeout, timeout, timeout, timeout, timer, timer, timestamp, timestamp, timestamp, timestamp, to, toCompletionStage, toFlowable, toFuture, toMaybe, toObservable, unsafeCreate, unsubscribeOn, using, using, wrap, zip, zip, zip, zip, zip, zip, zip, zip, zip, zipArray, zipWithModifier and TypeMethodDescriptionRuns multipleSingleSources and signals the events of the first one that signals (disposing the rest).ambArray(@NonNull SingleSource<? extends @NonNull T>... sources) Runs multipleSingleSources and signals the events of the first one that signals (disposing the rest).ambWith(@NonNull SingleSource<? extends T> other) Signals the event of this or the otherSingleSourcewhichever signals first.final TWaits in a blocking fashion until the currentSinglesignals a success value (which is returned) or an exception (which is propagated).final voidSubscribes to the currentSingleand blocks the current thread until it terminates.final voidblockingSubscribe(@NonNull SingleObserver<? super T> observer) Subscribes to the currentSingleand calls the appropriateSingleObservermethod on the current thread.final voidblockingSubscribe(@NonNull Consumer<? super T> onSuccess) Subscribes to the currentSingleand calls givenonSuccesscallback on the current thread when it completes normally.final voidblockingSubscribe(@NonNull Consumer<? super T> onSuccess, @NonNull Consumer<? super Throwable> onError) Subscribes to the currentSingleand calls the appropriate callback on the current thread when it terminates.cache()Stores the success value or exception from the currentSingleand replays it to lateSingleObservers.Casts the success value of the currentSingleinto the target type or signals aClassCastExceptionif not compatible.compose(@NonNull SingleTransformer<? super T, ? extends @NonNull R> transformer) Transform aSingleby applying a particularSingleTransformerfunction to it.static <@NonNull T>
@NonNull Observable<T> concat(@NonNull ObservableSource<? extends SingleSource<? extends @NonNull T>> sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided by anObservableSourcesequence.concat(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2) Returns aFlowablethat emits the items emitted by twoSingleSources, one after the other.concat(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3) Returns aFlowablethat emits the items emitted by threeSingleSources, one after the other.concat(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3, @NonNull SingleSource<? extends @NonNull T> source4) Returns aFlowablethat emits the items emitted by fourSingleSources, one after the other.Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided by anIterablesequence.concat(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided by aFlow.Publishersequence.concat(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, int prefetch) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided by aFlow.Publishersequence and prefetched by the specified amount.concatArray(@NonNull SingleSource<? extends @NonNull T>... sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided in an array.concatArrayDelayError(@NonNull SingleSource<? extends @NonNull T>... sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided in an array.concatArrayEager(@NonNull SingleSource<? extends @NonNull T>... sources) Concatenates a sequence ofSingleSourceeagerly into a single stream of values.concatArrayEagerDelayError(@NonNull SingleSource<? extends @NonNull T>... sources) Concatenates a sequence ofSingleSourceeagerly into a single stream of values.concatDelayError(@NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates theIterablesequence ofSingleSources into a single sequence by subscribing to eachSingleSource, one after the other, one at a time and delays any errors till the all innerSingleSources terminate as aFlowablesequence.concatDelayError(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates theFlow.Publishersequence ofSingleSources into a single sequence by subscribing to each innerSingleSource, one after the other, one at a time and delays any errors till the all inner and the outerPublisherterminate as aFlowablesequence.concatDelayError(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, int prefetch) Concatenates theFlow.Publishersequence ofSingleSources into a single sequence by subscribing to each innerSingleSource, one after the other, one at a time and delays any errors till the all inner and the outerPublisherterminate as aFlowablesequence.concatEager(@NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates anIterablesequence ofSingleSources eagerly into a single stream of values.concatEager(@NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates anIterablesequence ofSingleSources eagerly into a single stream of values and runs a limited number of the inner sources at once.concatEager(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates aFlow.Publishersequence ofSingleSources eagerly into a single stream of values.concatEager(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates aFlow.Publishersequence ofSingleSources eagerly into a single stream of values and runs a limited number of those innerSingleSources at once.concatEagerDelayError(@NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates anIterablesequence ofSingleSources eagerly into a single stream of values, delaying errors until all the inner sources terminate.concatEagerDelayError(@NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates anIterablesequence ofSingleSources eagerly into a single stream of values, delaying errors until all the inner sources terminate.concatEagerDelayError(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates aFlow.Publishersequence ofSingleSources eagerly into a single stream of values, delaying errors until all the inner and the outer sequence terminate.concatEagerDelayError(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency) Concatenates aFlow.Publishersequence ofSingleSources eagerly into a single stream of values, running at most the specified number of those innerSingleSources at once and delaying errors until all the inner and the outer sequence terminate.Returns aSinglethat is based on applying a specified function to the item emitted by the currentSingle, where that function returns aSingleSource.final @NonNull CompletableconcatMapCompletable(@NonNull Function<? super T, ? extends CompletableSource> mapper) Returns aCompletablethat completes based on applying a specified function to the item emitted by the currentSingle, where that function returns aCompletableSource.concatMapMaybe(@NonNull Function<? super T, ? extends MaybeSource<? extends @NonNull R>> mapper) Returns aMaybethat is based on applying a specified function to the item emitted by the currentSingle, where that function returns aMaybeSource.concatWith(@NonNull SingleSource<? extends T> other) Returns aFlowablethat emits the item emitted by the currentSingle, then the item emitted by the specifiedSingleSource.Signalstrueif the currentSinglesignals a success value that isObject.equals(Object)with the value provided.Signalstrueif the currentSinglesignals a success value that is equal with the value provided by calling aBiPredicate.create(@NonNull SingleOnSubscribe<@NonNull T> source) Provides an API (via a coldSingle) that bridges the reactive world with the callback-style world.Calls aSupplierfor each individualSingleObserverto return the actualSingleSourceto be subscribed to.Delays the emission of the success signal from the currentSingleby the specified amount.Delays the emission of the success or error signal from the currentSingleby the specified amount.Delays the emission of the success signal from the currentSingleby the specified amount.Delays the emission of the success or error signal from the currentSingleby the specified amount.delaySubscription(long time, @NonNull TimeUnit unit) Delays the actual subscription to the currentSingleuntil the given time delay elapsed.delaySubscription(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) Delays the actual subscription to the currentSingleuntil the given time delay elapsed.delaySubscription(@NonNull CompletableSource subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherCompletableSourcecompletes.delaySubscription(@NonNull ObservableSource<@NonNull U> subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherObservableSourcesignals its first value or completes.delaySubscription(@NonNull SingleSource<@NonNull U> subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherSingleSourcesignals success.delaySubscription(@NonNull Flow.Publisher<@NonNull U> subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherFlow.Publishersignals its first value or completes.dematerialize(@NonNull Function<? super T, @NonNull Notification<@NonNull R>> selector) Maps theNotificationsuccess value of the currentSingleback into normalonSuccess,onErrororonCompletesignals as aMaybesource.doAfterSuccess(@NonNull Consumer<? super T> onAfterSuccess) Calls the specified consumer with the success item after this item has been emitted to the downstream.doAfterTerminate(@NonNull Action onAfterTerminate) Calls the specified action after thisSinglesignalsonSuccessoronErroror gets disposed by the downstream.doOnDispose(@NonNull Action onDispose) Calls the sharedActionif aSingleObserversubscribed to the currentSingledisposes the commonDisposableit received viaonSubscribe.Calls the shared consumer with the error sent viaonErrorfor eachSingleObserverthat subscribes to the currentSingle.Calls the shared consumer with the error sent viaonErroror the value viaonSuccessfor eachSingleObserverthat subscribes to the currentSingle.doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe, @NonNull Action onDispose) Calls the appropriateonXXXmethod (shared between allSingleObservers) for the lifecycle events of the sequence (subscription, disposal).doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe) Calls the shared consumer with theDisposablesent through theonSubscribefor eachSingleObserverthat subscribes to the currentSingle.doOnSuccess(@NonNull Consumer<? super T> onSuccess) Calls the shared consumer with the success value sent viaonSuccessfor eachSingleObserverthat subscribes to the currentSingle.doOnTerminate(@NonNull Action onTerminate) Returns aSingleinstance that calls the givenonTerminatecallback just before thisSinglecompletes normally or with an exception.Signals aThrowablereturned by the callback function for each individualSingleObserver.Returns aSinglethat invokes a subscriber'sonErrormethod when the subscriber subscribes to it.Filters the success item of theSinglevia a predicate function and emitting it if the predicate returnstrue, completing otherwise.Returns aSinglethat is based on applying a specified function to the item emitted by the currentSingle, where that function returns aSingleSource.flatMap(@NonNull Function<? super T, ? extends SingleSource<? extends @NonNull R>> onSuccessMapper, @NonNull Function<? super Throwable, ? extends SingleSource<? extends @NonNull R>> onErrorMapper) Maps theonSuccessoronErrorsignals of the currentSingleinto aSingleSourceand emits thatSingleSource's signals.flatMap(@NonNull Function<? super T, ? extends SingleSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super T, ? super @NonNull U, ? extends @NonNull R> combiner) Returns aSinglethat emits the results of a specified function to the pair of values emitted by the currentSingleand a specified mappedSingleSource.final @NonNull CompletableflatMapCompletable(@NonNull Function<? super T, ? extends CompletableSource> mapper) Returns aCompletablethat completes based on applying a specified function to the item emitted by the currentSingle, where that function returns aCompletableSource.flatMapMaybe(@NonNull Function<? super T, ? extends MaybeSource<? extends @NonNull R>> mapper) Returns aMaybethat is based on applying a specified function to the item emitted by the currentSingle, where that function returns aMaybeSource.final <@NonNull R>
@NonNull Observable<R> flatMapObservable(@NonNull Function<? super T, ? extends ObservableSource<? extends @NonNull R>> mapper) Returns anObservablethat is based on applying a specified function to the item emitted by the currentSingle, where that function returns anObservableSource.flatMapPublisher(@NonNull Function<? super T, @NonNull ? extends Flow.Publisher<? extends @NonNull R>> mapper) Returns aFlowablethat emits items based on applying a specified function to the item emitted by the currentSingle, where that function returns aFlow.Publisher.flattenAsFlowable(@NonNull Function<? super T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) final <@NonNull U>
@NonNull Observable<U> flattenAsObservable(@NonNull Function<@NonNull ? super T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Maps the success value of the currentSingleinto anIterableand emits its items as anObservablesequence.flattenStreamAsFlowable(@NonNull Function<? super T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) final <@NonNull R>
@NonNull Observable<R> flattenStreamAsObservable(@NonNull Function<? super T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps the upstream succecss value into a JavaStreamand emits its items to the downstream consumer as anObservable.fromCallable(@NonNull Callable<? extends @NonNull T> callable) Returns aSinglethat invokes the givenCallablefor each incomingSingleObserverand emits its value or exception to them.fromCompletionStage(@NonNull CompletionStage<@NonNull T> stage) Signals the completion value or error of the given (hot)CompletionStage-based asynchronous calculation.fromFuture(@NonNull Future<? extends @NonNull T> future) Converts aFutureinto aSingleand awaits its outcome in a blocking fashion.Converts aFutureinto aSingleand awaits its outcome, or timeout, in a blocking fashion.fromMaybe(@NonNull MaybeSource<@NonNull T> maybe) Returns aSingleinstance that when subscribed to, subscribes to theMaybeSourceinstance and emitsonSuccessas a single item, turns anonCompleteintoNoSuchElementExceptionerror signal or forwards theonErrorsignal.fromMaybe(@NonNull MaybeSource<@NonNull T> maybe, @NonNull T defaultItem) Returns aSingleinstance that when subscribed to, subscribes to theMaybeSourceinstance and emitsonSuccessas a single item, emits thedefaultItemfor anonCompletesignal or forwards theonErrorsignal.fromObservable(@NonNull ObservableSource<? extends @NonNull T> observable) Wraps a specificObservableSourceinto aSingleand signals its single element or error.fromPublisher(@NonNull Flow.Publisher<? extends @NonNull T> publisher) Wraps a specificFlow.Publisherinto aSingleand signals its single element or error.fromSupplier(@NonNull Supplier<? extends @NonNull T> supplier) Returns aSinglethat invokes passed supplier and emits its result for each individualSingleObserverthat subscribes.hide()Hides the identity of the currentSingle, including theDisposablethat is sent to the downstream viaonSubscribe().final @NonNull CompletableReturns aSinglethat emits a specified item.lift(@NonNull SingleOperator<? extends @NonNull R, ? super T> lift) This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns aSinglewhich, when subscribed to, invokes theapply(SingleObserver)method of the providedSingleOperatorfor each individual downstreamSingleand allows the insertion of a custom operator by accessing the downstream'sSingleObserverduring this subscription phase and providing a newSingleObserver, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.Returns aSinglethat applies a specified function to the item emitted by the currentSingleand emits the result of this function application.final @NonNull Single<Notification<T>> Maps the signal types of thisSingleinto aNotificationof the same kind and emits it as a single success value to downstream.merge(@NonNull SingleSource<? extends SingleSource<? extends @NonNull T>> source) Flattens aSingleSourcethat emits aSingleSingleinto a singleSinglethat emits the item emitted by the nestedSingleSource, without any transformation.merge(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2) Flattens twoSingleSources into oneFlowablesequence, without any transformation.merge(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3) Flattens threeSingleSources into oneFlowablesequence, without any transformation.merge(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3, @NonNull SingleSource<? extends @NonNull T> source4) Flattens fourSingleSources into oneFlowablesequence, without any transformation.Merges anIterablesequence ofSingleSourceinstances into a singleFlowablesequence, running allSingleSources at once.merge(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Merges a sequence ofSingleSourceinstances emitted by aFlow.Publisherinto a singleFlowablesequence, running allSingleSources at once.mergeArray(SingleSource<? extends @NonNull T>... sources) Merges an array ofSingleSourceinstances into a singleFlowablesequence, running allSingleSources at once.mergeArrayDelayError(@NonNull SingleSource<? extends @NonNull T>... sources) Flattens an array ofSingleSources into oneFlowable, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceSingleSources without being interrupted by an error notification from one of them.mergeDelayError(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2) Flattens twoSingleSources into oneFlowable, without any transformation, delaying any error(s) until all sources succeed or fail.mergeDelayError(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3) Flattens twoSingleSources into oneFlowable, without any transformation, delaying any error(s) until all sources succeed or fail.mergeDelayError(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3, @NonNull SingleSource<? extends @NonNull T> source4) Flattens twoSingleSources into oneFlowable, without any transformation, delaying any error(s) until all sources succeed or fail.mergeDelayError(@NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Merges anIterablesequence ofSingleSourceinstances into oneFlowablesequence, running allSingleSources at once and delaying any error(s) until all sources succeed or fail.mergeDelayError(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Merges a sequence ofSingleSourceinstances emitted by aFlow.Publisherinto aFlowablesequence, running allSingleSources at once and delaying any error(s) until all sources succeed or fail.mergeWith(@NonNull SingleSource<? extends T> other) never()Returns a singleton instance of a never-signalingSingle(only callsonSubscribe).Signals the success item or the terminal signals of the currentSingleon the specifiedScheduler, asynchronously.Filters the items emitted by the currentSingle, only emitting its success value if that is an instance of the suppliedClass.Returns aMaybeinstance that if the currentSingleemits an error, it will emit anonCompleteand swallow the throwable.onErrorComplete(@NonNull Predicate<? super Throwable> predicate) Returns aMaybeinstance that if thisSingleemits an error and the predicate returnstrue, it will emit anonCompleteand swallow the throwable.onErrorResumeNext(@NonNull Function<? super Throwable, ? extends SingleSource<? extends T>> fallbackSupplier) Resumes the flow with aSingleSourcereturned for the failureThrowableof the currentSingleby a function instead of signaling the error viaonError.onErrorResumeWith(@NonNull SingleSource<? extends T> fallback) Resumes the flow with the givenSingleSourcewhen the currentSinglefails instead of signaling the error viaonError.onErrorReturn(@NonNull Function<Throwable, ? extends T> itemSupplier) Ends the flow with a success item returned by a function for theThrowableerror signaled by the currentSingleinstead of signaling the error viaonError.onErrorReturnItem(T item) Signals the specified value as success in case the currentSinglesignals an error.Nulls out references to the upstream producer and downstreamSingleObserverif the sequence is terminated or downstream callsdispose().repeat()Repeatedly re-subscribes to the currentSingleand emits each success value as aFlowablesequence.repeat(long times) Re-subscribes to the currentSingleat most the given number of times and emits each success value as aFlowablesequence.Re-subscribes to the currentSingleuntil the givenBooleanSupplierreturnstrueand emits the success items as aFlowablesequence.repeatWhen(@NonNull Function<? super Flowable<Object>, @NonNull ? extends Flow.Publisher<@NonNull ?>> handler) Re-subscribes to the currentSingleif theFlow.Publisherreturned by the handler function signals a value in response to a value signaled through theFlowablethe handler receives.retry()Repeatedly re-subscribes to the currentSingleindefinitely if it fails with anonError.retry(long times) Repeatedly re-subscribe at most the specified times to the currentSingleif it fails with anonError.Repeatedly re-subscribe at most times or until the predicate returnsfalse, whichever happens first if it fails with anonError.retry(@NonNull BiPredicate<? super Integer, ? super Throwable> predicate) Re-subscribe to the currentSingleif the given predicate returnstruewhen theSinglefails with anonError.Re-subscribe to the currentSingleif the given predicate returnstruewhen theSinglefails with anonError.Retries until the given stop function returnstrue.retryWhen(@NonNull Function<? super Flowable<Throwable>, @NonNull ? extends Flow.Publisher<@NonNull ?>> handler) Re-subscribes to the currentSingleif and when theFlow.Publisherreturned by the handler function signals a value.final voidsafeSubscribe(@NonNull SingleObserver<? super T> observer) Wraps the givenSingleObserver, catches anyRuntimeExceptions thrown by itsSingleObserver.onSubscribe(Disposable),SingleObserver.onSuccess(Object)orSingleObserver.onError(Throwable)methods* and routes those to the global error handler viaRxJavaPlugins.onError(Throwable).sequenceEqual(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2) Compares twoSingleSources and emitstrueif they emit the same value (compared viaObject.equals(Object)).startWith(@NonNull CompletableSource other) Returns aFlowablewhich first runs the otherCompletableSourcethen the currentSingleif the other completed normally.startWith(@NonNull MaybeSource<T> other) Returns aFlowablewhich first runs the otherMaybeSourcethen the currentSingleif the other succeeded or completed normally.final @NonNull Observable<T> startWith(@NonNull ObservableSource<T> other) Returns anObservablewhich first delivers the events of the otherObservableSourcethen runs the currentSingle.startWith(@NonNull SingleSource<T> other) Returns aFlowablewhich first runs the otherSingleSourcethen the currentSingleif the other succeeded normally.startWith(@NonNull Flow.Publisher<T> other) Returns aFlowablewhich first delivers the events of the otherFlow.Publisherthen runs the currentSingle.final @NonNull DisposableSubscribes to aSinglebut ignore its emission or notification.final voidsubscribe(@NonNull SingleObserver<? super T> observer) Subscribes the givenSingleObserverto thisSingleSourceinstance.final @NonNull DisposableSubscribes to aSingleand provides a composite callback to handle the item it emits or any error notification it issues.final @NonNull DisposableSubscribes to aSingleand provides a callback to handle the item it emits.final @NonNull DisposableSubscribes to aSingleand provides callbacks to handle the item it emits or any error notification it issues.final @NonNull Disposablesubscribe(@NonNull Consumer<? super T> onSuccess, @NonNull Consumer<? super Throwable> onError, @NonNull DisposableContainer container) Wraps the given onXXX callbacks into aDisposableSingleObserver, adds it to the givenDisposableContainerand ensures, that if the upstream terminates or this particularDisposableis disposed, theSingleObserveris removed from the given container.subscribeOn(@NonNull Scheduler scheduler) final <@NonNull E extends SingleObserver<? super @NonNull T>>
EsubscribeWith(@NonNull E observer) Subscribes a givenSingleObserver(subclass) to thisSingleand returns the givenSingleObserveras is.switchOnNext(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Switches betweenSingleSources emitted by the sourceFlow.Publisherwhenever a newSingleSourceis emitted, disposing the previously runningSingleSource, exposing the success items as aFlowablesequence.switchOnNextDelayError(@NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Switches betweenSingleSources emitted by the sourceFlow.Publisherwhenever a newSingleSourceis emitted, disposing the previously runningSingleSource, exposing the success items as aFlowablesequence and delaying all errors from all of them until all terminate.takeUntil(@NonNull CompletableSource other) Returns aSinglethat emits the item emitted by the currentSingleuntil aCompletableSourceterminates.takeUntil(@NonNull SingleSource<? extends @NonNull E> other) Returns aSinglethat emits the item emitted by the currentSingleuntil a secondSingleemits an item.takeUntil(@NonNull Flow.Publisher<@NonNull E> other) Returns aSinglethat emits the item emitted by the currentSingleuntil aFlow.Publisheremits an item or completes.final @NonNull TestObserver<T> test()Creates aTestObserverand subscribes it to thisSingle.final @NonNull TestObserver<T> test(boolean dispose) Creates aTestObserveroptionally in cancelled state, then subscribes it to thisSingle.Measures the time (in milliseconds) between the subscription and success item emission of the currentSingleand signals it as a tuple (Timed) success value.timeInterval(@NonNull Scheduler scheduler) Measures the time (in milliseconds) between the subscription and success item emission of the currentSingleand signals it as a tuple (Timed) success value.timeInterval(@NonNull TimeUnit unit) Measures the time between the subscription and success item emission of the currentSingleand signals it as a tuple (Timed) success value.timeInterval(@NonNull TimeUnit unit, @NonNull Scheduler scheduler) Measures the time between the subscription and success item emission of the currentSingleand signals it as a tuple (Timed) success value.Signals aTimeoutExceptionif the currentSingledoesn't signal a success value within the specified timeout window.Signals aTimeoutExceptionif the currentSingledoesn't signal a success value within the specified timeout window.timeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull SingleSource<? extends T> fallback) Runs the currentSingleand if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSourcesubscribed to.Runs the currentSingleand if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSourcesubscribed to.Signals success with 0L value after the given delay when aSingleObserversubscribes.Signals success with 0L value on the specifiedSchedulerafter the given delay when aSingleObserversubscribes.final <R> Rto(@NonNull SingleConverter<T, ? extends R> converter) Calls the specified converter function during assembly time and returns its resulting value.final @NonNull CompletionStage<T> Signals the upstream success item (or error) via aCompletionStage.Converts thisSingleinto aFlowable.toFuture()Returns aFuturerepresenting the single value emitted by thisSingle.toMaybe()Converts thisSingleinto aMaybe.final @NonNull Observable<T> Converts thisSingleinto anObservable.unsafeCreate(@NonNull SingleSource<@NonNull T> onSubscribe) Advanced use only: creates aSingleinstance without any safeguards by using a callback that is called with aSingleObserver.unsubscribeOn(@NonNull Scheduler scheduler) Returns aSinglewhich makes sure when aSingleObserverdisposes theDisposable, that call is propagated up on the specifiedScheduler.using(@NonNull Supplier<@NonNull U> resourceSupplier, @NonNull Function<? super @NonNull U, ? extends SingleSource<? extends @NonNull T>> sourceSupplier, @NonNull Consumer<? super @NonNull U> resourceCleanup) Allows using and disposing a resource while running aSingleSourceinstance generated from that resource (similar to a try-with-resources).using(@NonNull Supplier<@NonNull U> resourceSupplier, @NonNull Function<? super @NonNull U, ? extends SingleSource<? extends @NonNull T>> sourceSupplier, @NonNull Consumer<? super @NonNull U> resourceCleanup, boolean eager) Allows using and disposing a resource while running aSingleSourceinstance generated from that resource (similar to a try-with-resources).wrap(@NonNull SingleSource<@NonNull T> source) static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull T9, @NonNull R>
@NonNull Single<R> zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull SingleSource<? extends @NonNull T7> source7, @NonNull SingleSource<? extends @NonNull T8> source8, @NonNull SingleSource<? extends @NonNull T9> source9, @NonNull Function9<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? super @NonNull T9, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to nine items emitted by nine otherSingleSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull R>
@NonNull Single<R> zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull SingleSource<? extends @NonNull T7> source7, @NonNull SingleSource<? extends @NonNull T8> source8, @NonNull Function8<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? super @NonNull T8, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to eight items emitted by eight otherSingleSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull R>
@NonNull Single<R> zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull SingleSource<? extends @NonNull T7> source7, @NonNull Function7<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? super @NonNull T7, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to seven items emitted by seven otherSingleSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull R>
@NonNull Single<R> zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull Function6<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? super @NonNull T6, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to six items emitted by six otherSingleSources.static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull R>
@NonNull Single<R> zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull Function5<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? super @NonNull T5, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to five items emitted by five otherSingleSources.zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull Function4<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? super @NonNull T4, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to four items emitted by four otherSingleSources.zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull Function3<? super @NonNull T1, ? super @NonNull T2, ? super @NonNull T3, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to three items emitted by three otherSingleSources.zip(@NonNull SingleSource<? extends @NonNull T1> source1, @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull BiFunction<? super @NonNull T1, ? super @NonNull T2, ? extends @NonNull R> zipper) Returns aSinglethat emits the results of a specified combiner function applied to two items emitted by two otherSingleSources.zip(@NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, @NonNull Function<? super Object[], ? extends @NonNull R> zipper) Waits until allSingleSourcesources provided by theIterablesequence signal a success value and calls a zipper function with an array of these values to return a result to be emitted to the downstream.zipArray(@NonNull Function<? super Object[], ? extends @NonNull R> zipper, @NonNull SingleSource<? extends @NonNull T>... sources) Waits until allSingleSourcesources provided via an array signal a success value and calls a zipper function with an array of these values to return a result to be emitted to downstream.zipWith(@NonNull SingleSource<@NonNull U> other, @NonNull BiFunction<? super T, ? super @NonNull U, ? extends @NonNull R> zipper) Returns aSinglethat emits the result of applying a specified function to the pair of items emitted by the currentSingleand another specifiedSingleSource.
-
Method Details
-
create
Creates a fresh SingleSubject.- Type Parameters:
T- the value type received and emitted- Returns:
- the new SingleSubject instance
-
onSubscribe
Description copied from interface:SingleObserverProvides theSingleObserverwith the means of cancelling (disposing) the connection (channel) with the Single in both synchronous (from withinonSubscribe(Disposable)itself) and asynchronous manner.- Specified by:
onSubscribein interfaceSingleObserver<T>- Parameters:
d- the Disposable instance whoseDisposable.dispose()can be called anytime to cancel the connection
-
onSuccess
Description copied from interface:SingleObserverNotifies theSingleObserverwith a single item and that theSinglehas finished sending push-based notifications.The
Singlewill not call this method if it callsSingleObserver.onError(Throwable).- Specified by:
onSuccessin interfaceSingleObserver<T>- Parameters:
value- the item emitted by theSingle
-
onError
Description copied from interface:SingleObserverNotifies theSingleObserverthat theSinglehas experienced an error condition.If the
Singlecalls this method, it will not thereafter callSingleObserver.onSuccess(T).- Specified by:
onErrorin interfaceSingleObserver<T>- Parameters:
e- the exception encountered by theSingle
-
subscribeActual
Description copied from class:SingleImplement this method in subclasses to handle the incomingSingleObservers.There is no need to call any of the plugin hooks on the current
Singleinstance or theSingleObserver; all hooks and basic safeguards have been applied bySingle.subscribe(SingleObserver)before this method gets called.- Specified by:
subscribeActualin classSingle<T>- Parameters:
observer- theSingleObserverto handle, notnull
-
getValue
-
hasValue
public boolean hasValue()Returns true if this SingleSubject was terminated with a success value.- Returns:
- true if this SingleSubject was terminated with a success value
-
getThrowable
-
hasThrowable
public boolean hasThrowable()Returns true if this SingleSubject has been terminated with an error.- Returns:
- true if this SingleSubject has been terminated with an error
-
hasObservers
public boolean hasObservers()Returns true if this SingleSubject has observers.- Returns:
- true if this SingleSubject has observers
-