Class Single<T>
- Type Parameters:
T- the type of the item emitted by theSingle
- All Implemented Interfaces:
SingleSource<T>
- Direct Known Subclasses:
SingleSubject
Single class implements the Reactive Pattern for a single value response.
Single behaves similarly to Observable except that it can only emit either a single successful
value or an error (there is no onComplete notification as there is for an Observable).
The Single class implements the SingleSource base interface and the default consumer
type it interacts with is the SingleObserver via the subscribe(SingleObserver) method.
The Single operates with the following sequential protocol:
onSubscribe (onSuccess | onError)?
Note that onSuccess and onError are mutually exclusive events; unlike Observable,
onSuccess is never followed by onError.
Like Observable, a running Single can be stopped through the Disposable instance
provided to consumers through SingleObserver.onSubscribe(Disposable).
Like an Observable, a Single is lazy, can be either "hot" or "cold", synchronous or
asynchronous. Single instances returned by the methods of this class are cold
and there is a standard hot implementation in the form of a subject:
SingleSubject.
The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
See Flowable or Observable for the
implementation of the Reactive Pattern for a stream or vector of values.
For more information see the ReactiveX documentation.
Example:
Disposable d = Single.just("Hello World")
.delay(10, TimeUnit.SECONDS, Schedulers.io())
.subscribeWith(new DisposableSingleObserver<String>() {
@Override
public void onStart() {
System.out.println("Started");
}
@Override
public void onSuccess(String value) {
System.out.println("Success: " + value);
}
@Override
public void onError(Throwable error) {
error.printStackTrace();
}
});
Thread.sleep(5000);
d.dispose();
Note that by design, subscriptions via subscribe(SingleObserver) can't be disposed
from the outside (hence the
void return of the subscribe(SingleObserver) method) and it is the
responsibility of the implementor of the SingleObserver to allow this to happen.
RxJava supports such usage with the standard
DisposableSingleObserver instance.
For convenience, the subscribeWith(SingleObserver) method is provided as well to
allow working with a SingleObserver (or subclass) instance to be applied with in
a fluent manner (such as in the example above).
- Since:
- 2.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier 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 @NonNull 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 @NonNull T> observer) Subscribes to the currentSingleand calls the appropriateSingleObservermethod on the current thread.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess) Subscribes to the currentSingleand calls givenonSuccesscallback on the current thread when it completes normally.final voidblockingSubscribe(@NonNull Consumer<? super @NonNull 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.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.concatMap(@NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) 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 @NonNull 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 @NonNull 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 @NonNull 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 @NonNull T, @NonNull Notification<@NonNull R>> selector) Maps theNotificationsuccess value of the currentSingleback into normalonSuccess,onErrororonCompletesignals as aMaybesource.doAfterSuccess(@NonNull Consumer<? super @NonNull 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 @NonNull 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 @NonNull 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 @NonNull T, ? extends SingleSource<? extends @NonNull U>> mapper, @NonNull BiFunction<? super @NonNull 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 @NonNull 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 @NonNull 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 @NonNull 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 @NonNull 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 @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) final <@NonNull U>
@NonNull Observable<U> flattenAsObservable(@NonNull Function<@NonNull ? super @NonNull 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 @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) final <@NonNull R>
@NonNull Observable<R> flattenStreamAsObservable(@NonNull Function<? super @NonNull 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.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 @NonNull 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 @NonNull T>> fallbackSupplier) Resumes the flow with aSingleSourcereturned for the failureThrowableof the currentSingleby a function instead of signaling the error viaonError.onErrorResumeWith(@NonNull SingleSource<? extends @NonNull T> fallback) Resumes the flow with the givenSingleSourcewhen the currentSinglefails instead of signaling the error viaonError.Ends the flow with a success item returned by a function for theThrowableerror signaled by the currentSingleinstead of signaling the error viaonError.onErrorReturnItem(@NonNull 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 @NonNull 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<@NonNull T> other) Returns aFlowablewhich first runs the otherMaybeSourcethen the currentSingleif the other succeeded or completed normally.final @NonNull Observable<T> startWith(@NonNull ObservableSource<@NonNull T> other) Returns anObservablewhich first delivers the events of the otherObservableSourcethen runs the currentSingle.startWith(@NonNull SingleSource<@NonNull T> other) Returns aFlowablewhich first runs the otherSingleSourcethen the currentSingleif the other succeeded normally.startWith(@NonNull Flow.Publisher<@NonNull 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 @NonNull T> observer) Subscribes the givenSingleObserverto thisSingleSourceinstance.final @NonNull Disposablesubscribe(@NonNull BiConsumer<@Nullable ? super @NonNull T, @Nullable ? super Throwable> onCallback) Subscribes 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 Disposablesubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super Throwable> onError) Subscribes to aSingleand provides callbacks to handle the item it emits or any error notification it issues.final @NonNull Disposablesubscribe(@NonNull Consumer<? super @NonNull 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.protected abstract voidsubscribeActual(@NonNull SingleObserver<? super @NonNull T> observer) Implement this method in subclasses to handle the incomingSingleObservers.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 @NonNull 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<@NonNull 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 @NonNull 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.
-
Constructor Details
-
Single
public Single()
-
-
Method Details
-
amb
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> amb(@NonNull @NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Runs multipleSingleSources and signals the events of the first one that signals (disposing the rest).
- Scheduler:
ambdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- theIterablesequence of sources. A subscription to each source will occur in the same order as in thisIterable.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
ambArray
@CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public static <@NonNull T> @NonNull Single<T> ambArray(@NonNull @NonNull SingleSource<? extends @NonNull T>... sources) Runs multipleSingleSources and signals the events of the first one that signals (disposing the rest).
- Scheduler:
ambArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- the array of sources. A subscription to each source will occur in the same order as in this array.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided by anIterablesequence.
- Type Parameters:
T- the value type- Parameters:
sources- theIterablesequence ofSingleSourceinstances- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Observable<T> concat(@NonNull @NonNull ObservableSource<? extends SingleSource<? extends @NonNull T>> sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided by anObservableSourcesequence.
- Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
sources- theObservableSourceofSingleSourceinstances- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @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.
- Type Parameters:
T- the value type- Parameters:
sources- thePublisherofSingleSourceinstances- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @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.
- Type Parameters:
T- the value type- Parameters:
sources- thePublisherofSingleSourceinstancesprefetch- the number ofSingleSources to prefetch from thePublisher- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifprefetchis non-positive- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2) Returns aFlowablethat emits the items emitted by twoSingleSources, one after the other.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be concatenatedsource2- aSingleSourceto be concatenated- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
concat
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2, @NonNull @NonNull SingleSource<? extends @NonNull T> source3) Returns aFlowablethat emits the items emitted by threeSingleSources, one after the other.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be concatenatedsource2- aSingleSourceto be concatenatedsource3- aSingleSourceto be concatenated- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
concat
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2, @NonNull @NonNull SingleSource<? extends @NonNull T> source3, @NonNull @NonNull SingleSource<? extends @NonNull T> source4) Returns aFlowablethat emits the items emitted by fourSingleSources, one after the other.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be concatenatedsource2- aSingleSourceto be concatenatedsource3- aSingleSourceto be concatenatedsource4- aSingleSourceto be concatenated- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
concatArray
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> concatArray(@NonNull @NonNull SingleSource<? extends @NonNull T>... sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided in an array.
- Type Parameters:
T- the value type- Parameters:
sources- the array ofSingleSourceinstances- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
-
concatArrayDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> concatArrayDelayError(@NonNull @NonNull SingleSource<? extends @NonNull T>... sources) Concatenate the single values, in a non-overlapping fashion, of theSingleSources provided in an array.
- Type Parameters:
T- the value type- Parameters:
sources- the array ofSingleSourceinstances- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatArrayEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> concatArrayEager(@NonNull @NonNull SingleSource<? extends @NonNull T>... sources) Concatenates a sequence ofSingleSourceeagerly into a single stream of values.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSources. The operator buffers the value emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofSingleSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatArrayEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> concatArrayEagerDelayError(@NonNull @NonNull SingleSource<? extends @NonNull T>... sources) Concatenates a sequence ofSingleSourceeagerly into a single stream of values.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSources. The operator buffers the value emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofSingleSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @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.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- theIterablesequence ofSingleSources- Returns:
- the new
Flowablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @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.
- Backpressure:
concatDelayErrorfully supports backpressure.- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- thePublishersequence ofSingleSources- Returns:
- the new
Flowablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @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.
- Backpressure:
concatDelayErrorfully supports backpressure.- Scheduler:
concatDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- thePublishersequence ofSingleSourcesprefetch- The number of upstream items to prefetch so that fresh items are ready to be mapped when a previousSingleSourceterminates. The operator replenishes after half of the prefetch amount has been consumed and turned intoSingleSources.- Returns:
- the new
Flowablewith the concatenating behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifprefetchis non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates anIterablesequence ofSingleSources eagerly into a single stream of values.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSources. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- anIterablesequence ofSingleSourcethat need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @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.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSources. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- anIterablesequence ofSingleSourcethat need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerSingleSources;Integer.MAX_VALUEis interpreted as all innerSingleSources can be active at the same time- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Concatenates aFlow.Publishersequence ofSingleSources eagerly into a single stream of values.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
SingleSources as they are observed. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException. - Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofSingleSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @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.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
SingleSources as they are observed. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException. - Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofSingleSources that need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerSingleSources;Integer.MAX_VALUEis interpreted as all innerSingleSources can be active at the same time- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @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.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSources. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- anIterablesequence ofSingleSourcethat need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @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.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSources. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream.
- Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- anIterablesequence ofSingleSourcethat need to be eagerly concatenatedmaxConcurrency- the maximum number of concurrently running innerSingleSources;Integer.MAX_VALUEis interpreted as all innerSingleSources can be active at the same time- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @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.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
SingleSources as they are observed. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException. - Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofSingleSources that need to be eagerly concatenated- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @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.
Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
SingleSources as they are observed. The operator buffers the values emitted by theseSingleSources and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisheris expected to support backpressure. Violating this assumption, the operator will signalMissingBackpressureException. - Scheduler:
- This method does not operate by default on a particular
Scheduler.
- Type Parameters:
T- the value type- Parameters:
sources- a sequence ofSingleSources that need to be eagerly concatenatedmaxConcurrency- the number of innerSingleSources to run at once- Returns:
- the new
Flowableinstance with the specified concatenation behavior - Throws:
NullPointerException- ifsourcesisnullIllegalArgumentException- ifmaxConcurrencyis non-positive- Since:
- 3.0.0
-
create
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> create(@NonNull @NonNull SingleOnSubscribe<@NonNull T> source) Provides an API (via a coldSingle) that bridges the reactive world with the callback-style world.
Example:
Single.<Event>create(emitter -> { Callback listener = new Callback() { @Override public void onEvent(Event e) { emitter.onSuccess(e); } @Override public void onFailure(Exception e) { emitter.onError(e); } }; AutoCloseable c = api.someMethod(listener); emitter.setCancellable(c::close); });Whenever a
SingleObserversubscribes to the returnedSingle, the providedSingleOnSubscribecallback is invoked with a fresh instance of aSingleEmitterthat will interact only with that specificSingleObserver. If thisSingleObserverdisposes the flow (makingSingleEmitter.isDisposed()returntrue), other observers subscribed to the same returnedSingleare not affected.- Scheduler:
createdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
source- the emitter that is called when aSingleObserversubscribes to the returnedSingle- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsourceisnull- See Also:
-
defer
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> defer(@NonNull @NonNull Supplier<? extends @NonNull SingleSource<? extends @NonNull T>> supplier) Calls aSupplierfor each individualSingleObserverto return the actualSingleSourceto be subscribed to.
- Scheduler:
deferdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
supplier- theSupplierthat is called for each individualSingleObserverand returns aSingleSourceinstance to subscribe to- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsupplierisnull
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> error(@NonNull @NonNull Supplier<? extends @NonNull Throwable> supplier) Signals aThrowablereturned by the callback function for each individualSingleObserver.
- Scheduler:
errordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
supplier- theSupplierthat is called for each individualSingleObserverand returns aThrowableinstance to be emitted.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsupplierisnull
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> error(@NonNull @NonNull Throwable throwable) Returns aSinglethat invokes a subscriber'sonErrormethod when the subscriber subscribes to it.
- Scheduler:
errordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the item (ostensibly) emitted by theSingle- Parameters:
throwable- the particularThrowableto pass toonError- Returns:
- the new
Singlethat invokes the subscriber'sonErrormethod when the subscriber subscribes to it - Throws:
NullPointerException- ifthrowableisnull- See Also:
-
fromCallable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromCallable(@NonNull @NonNull Callable<? extends @NonNull T> callable) Returns aSinglethat invokes the givenCallablefor each incomingSingleObserverand emits its value or exception to them.Allows you to defer execution of passed function until
SingleObserversubscribes to theSingle. It makes passed function "lazy". Result of the function invocation will be emitted by theSingle.
- Scheduler:
fromCallabledoes not operate by default on a particularScheduler.- Error handling:
- If the
Callablethrows an exception, the respectiveThrowableis delivered to the downstream viaSingleObserver.onError(Throwable), except when the downstream has disposed thisSinglesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the type of the item emitted by theSingle.- Parameters:
callable- function which execution should be deferred, it will be invoked whenSingleObserverwill subscribe to theSingle.- Returns:
- the new
SinglewhoseSingleObservers' subscriptions trigger an invocation of the given function. - Throws:
NullPointerException- ifcallableisnull- See Also:
-
fromFuture
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> fromFuture(@NonNull @NonNull Future<? extends @NonNull T> future) Converts aFutureinto aSingleand awaits its outcome in a blocking fashion.
The operator calls
Future.get(), which is a blocking method, on the subscription thread. It is recommended applyingsubscribeOn(Scheduler)to move this blocking wait to a background thread, and if theSchedulersupports it, interrupt the wait when the flow is disposed.A non-
nullvalue is then emitted viaonSuccessor any exception is emitted viaonError. If theFuturecompletes withnull, aNullPointerExceptionis signaled.- Scheduler:
fromFuturedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingSingle- Parameters:
future- the sourceFuture- Returns:
- the new
Singlethat emits the item from the sourceFuture - Throws:
NullPointerException- iffutureisnull- See Also:
-
fromFuture
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> fromFuture(@NonNull @NonNull Future<? extends @NonNull T> future, long timeout, @NonNull @NonNull TimeUnit unit) Converts aFutureinto aSingleand awaits its outcome, or timeout, in a blocking fashion.
The operator calls
Future.get(long, TimeUnit), which is a blocking method, on the subscription thread. It is recommended applyingsubscribeOn(Scheduler)to move this blocking wait to a background thread, and if theSchedulersupports it, interrupt the wait when the flow is disposed.A non-
nullvalue is then emitted viaonSuccessor any exception is emitted viaonError. If theFuturecompletes withnull, aNullPointerExceptionis signaled.- Scheduler:
fromFuturedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of object that theFuturereturns, and also the type of item to be emitted by the resultingSingle- Parameters:
future- the sourceFuturetimeout- the maximum time to wait before callinggetunit- theTimeUnitof thetimeoutargument- Returns:
- the new
Singlethat emits the item from the sourceFuture - Throws:
NullPointerException- iffutureorunitisnull- See Also:
-
fromMaybe
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromMaybe(@NonNull @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.
- Scheduler:
fromMaybedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of theMaybeSourceelement- Parameters:
maybe- theMaybeSourceinstance to subscribe to, notnull- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifmaybeisnull- Since:
- 3.0.0
-
fromMaybe
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromMaybe(@NonNull @NonNull MaybeSource<@NonNull T> maybe, @NonNull @NonNull T defaultItem) Returns aSingleinstance that when subscribed to, subscribes to theMaybeSourceinstance and emitsonSuccessas a single item, emits thedefaultItemfor anonCompletesignal or forwards theonErrorsignal.
- Scheduler:
fromMaybedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of theMaybeSourceelement- Parameters:
maybe- theMaybeSourceinstance to subscribe to, notnulldefaultItem- the item to signal if the currentMaybeSourceis empty- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifmaybeordefaultItemisnull- Since:
- 3.0.0
-
fromPublisher
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromPublisher(@NonNull @NonNull Flow.Publisher<? extends @NonNull T> publisher) Wraps a specificFlow.Publisherinto aSingleand signals its single element or error.
If the source
Publisheris empty, aNoSuchElementExceptionis signaled. If the source has more than one element, anIndexOutOfBoundsExceptionis signaled.The
Publishermust follow the Reactive Streams specification. Violating the specification may result in undefined behavior.If possible, use
create(SingleOnSubscribe)to create a source-likeSingleinstead.Note that even though
Publisherappears to be a functional interface, it is not recommended to implement it through a lambda as the specification requires state management that is not achievable with a stateless lambda.- Backpressure:
- The
publisheris consumed in an unbounded fashion but will be cancelled if it produced more than one item. - Scheduler:
fromPublisherdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
publisher- the sourcePublisherinstance, notnull- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifpublisherisnull- See Also:
-
fromObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromObservable(@NonNull @NonNull ObservableSource<? extends @NonNull T> observable) Wraps a specificObservableSourceinto aSingleand signals its single element or error.
If the
ObservableSourceis empty, aNoSuchElementExceptionis signaled. If the source has more than one element, anIndexOutOfBoundsExceptionis signaled.- Scheduler:
fromObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of the item emitted by theSingle.- Parameters:
observable- the source sequence to wrap, notnull- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifobservableisnull
-
fromSupplier
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromSupplier(@NonNull @NonNull Supplier<? extends @NonNull T> supplier) Returns aSinglethat invokes passed supplier and emits its result for each individualSingleObserverthat subscribes.Allows you to defer execution of passed function until a
SingleObserversubscribes to theSingle. It makes passed function "lazy". Result of the function invocation will be emitted by theSingle.
- Scheduler:
fromSupplierdoes not operate by default on a particularScheduler.- Error handling:
- If the
Supplierthrows an exception, the respectiveThrowableis delivered to the downstream viaSingleObserver.onError(Throwable), except when the downstream has disposed thisSinglesource. In this latter case, theThrowableis delivered to the global error handler viaRxJavaPlugins.onError(Throwable)as anUndeliverableException.
- Type Parameters:
T- the type of the item emitted by theSingle.- Parameters:
supplier- function which execution should be deferred, it will be invoked whenSingleObserversubscribes to theSingle.- Returns:
- the new
SinglewhoseSingleObservers' subscriptions trigger an invocation of the given function. - Throws:
NullPointerException- ifsupplierisnull- Since:
- 3.0.0
- See Also:
-
just
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> just(@NonNull T item) Returns aSinglethat emits a specified item.
To convert any object into a
Singlethat emits that object, pass that object into thejustmethod.- Scheduler:
justdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the type of that item- Parameters:
item- the item to emit- Returns:
- the new
Singlethat emitsitem - Throws:
NullPointerException- ifitemisnull- See Also:
-
merge
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Merges anIterablesequence ofSingleSourceinstances into a singleFlowablesequence, running allSingleSources at once.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
SingleSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceSingleSources are disposed. If more than oneSingleSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Iterable)to merge sources and terminate only when all sourceSingleSources have completed or failed with an error.
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- theIterablesequence ofSingleSourcesources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
- See Also:
-
merge
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull Flow.Publisher<@NonNull ? extends SingleSource<? extends @NonNull T>> sources) Merges a sequence ofSingleSourceinstances emitted by aFlow.Publisherinto a singleFlowablesequence, running allSingleSources at once.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
SingleSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceSingleSources are disposed. If more than oneSingleSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(Publisher)to merge sources and terminate only when all sourceSingleSources have completed or failed with an error.
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- thePublisheremitting a sequence ofSingleSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.0
- See Also:
-
merge
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> merge(@NonNull @NonNull SingleSource<? extends SingleSource<? extends @NonNull T>> source) Flattens aSingleSourcethat emits aSingleSingleinto a singleSinglethat emits the item emitted by the nestedSingleSource, without any transformation.
- Scheduler:
mergedoes not operate by default on a particularScheduler.- The resulting
Singleemits the outer source's or the innerSingleSource'sThrowableas is. Unlike the othermerge()operators, this operator won't and can't produce aCompositeExceptionbecause there is only one possibility for the outer or the innerSingleSourceto emit anonErrorsignal. Therefore, there is no need for amergeDelayError(SingleSource<SingleSource<T>>)operator.
- Type Parameters:
T- the value type of the sources and the output- Parameters:
source- aSinglethat emits aSingle- Returns:
- the new
Singlethat emits the item that is the result of flattening theSingleemitted bysource - Throws:
NullPointerException- ifsourceisnull- See Also:
-
merge
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2) Flattens twoSingleSources into oneFlowablesequence, without any transformation.
You can combine items emitted by multiple
SingleSources so that they appear as a singleFlowable, by using themergemethod.- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
SingleSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceSingleSources are disposed. If more than oneSingleSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(SingleSource, SingleSource)to merge sources and terminate only when all sourceSingleSources have completed or failed with an error.
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be mergedsource2- aSingleSourceto be merged- Returns:
- the new
Flowablethat emits all of the items emitted by the sourceSingleSources - Throws:
NullPointerException- ifsource1orsource2isnull- See Also:
-
merge
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2, @NonNull @NonNull SingleSource<? extends @NonNull T> source3) Flattens threeSingleSources into oneFlowablesequence, without any transformation.
You can combine items emitted by multiple
SingleSources so that they appear as a singleFlowable, by themergemethod.- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
SingleSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceSingleSources are disposed. If more than oneSingleSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(SingleSource, SingleSource, SingleSource)to merge sources and terminate only when all sourceSingleSources have completed or failed with an error.
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be mergedsource2- aSingleSourceto be mergedsource3- aSingleSourceto be merged- Returns:
- the new
Flowablethat emits all of the items emitted by the sourceSingleSources - Throws:
NullPointerException- ifsource1,source2orsource3isnull- See Also:
-
merge
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2, @NonNull @NonNull SingleSource<? extends @NonNull T> source3, @NonNull @NonNull SingleSource<? extends @NonNull T> source4) Flattens fourSingleSources into oneFlowablesequence, without any transformation.
You can combine items emitted by multiple
SingleSources so that they appear as a singleFlowable, by themergemethod.- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergedoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
SingleSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceSingleSources are disposed. If more than oneSingleSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeDelayError(SingleSource, SingleSource, SingleSource, SingleSource)to merge sources and terminate only when all sourceSingleSources have completed or failed with an error.
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be mergedsource2- aSingleSourceto be mergedsource3- aSingleSourceto be mergedsource4- aSingleSourceto be merged- Returns:
- the new
Flowablethat emits all of the items emitted by the sourceSingleSources - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- See Also:
-
mergeArray
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> mergeArray(SingleSource<? extends @NonNull T>... sources) Merges an array ofSingleSourceinstances into a singleFlowablesequence, running allSingleSources at once.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArraydoes not operate by default on a particularScheduler.- Error handling:
- If any of the source
SingleSources signal aThrowableviaonError, the resultingFlowableterminates with thatThrowableand all other sourceSingleSources are disposed. If more than oneSingleSourcesignals an error, the resultingFlowablemay terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeExceptioncontaining two or more of the various error signals.Throwables that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)method asUndeliverableExceptionerrors. Similarly,Throwables signaled by source(s) after the returnedFlowablehas been cancelled or terminated with a (composite) error will be sent to the same global error handler. UsemergeArrayDelayError(SingleSource...)to merge sources and terminate only when all sourceSingleSources have completed or failed with an error.
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- the array sequence ofSingleSourcesources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeArrayDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @SafeVarargs @NonNull public static <@NonNull T> @NonNull Flowable<T> mergeArrayDelayError(@NonNull @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.
This behaves like
merge(Publisher)except that if any of the mergedSingleSources notify of an error viaonError,mergeArrayDelayErrorwill refrain from propagating that error notification until all of the mergedSingleSources have finished emitting items.Even if multiple merged
SingleSources sendonErrornotifications,mergeArrayDelayErrorwill only invoke theonErrormethod of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArrayDelayErrordoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common element base type- Parameters:
sources- the array ofSingleSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- See Also:
-
mergeDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @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.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.9 - experimental
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- theIterablesequence ofSingleSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.2
- See Also:
-
mergeDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @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.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.9 - experimental
- Type Parameters:
T- the common and resulting value type- Parameters:
sources- theFlowablesequence ofSingleSources- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 2.2
- See Also:
-
mergeDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2) Flattens twoSingleSources into oneFlowable, without any transformation, delaying any error(s) until all sources succeed or fail.
You can combine items emitted by multiple
SingleSources so that they appear as oneFlowable, by using themergeDelayErrormethod.- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.9 - experimental
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be mergedsource2- aSingleSourceto be merged- Returns:
- the new
Flowablethat emits all of the items emitted by the sourceSingleSources - Throws:
NullPointerException- ifsource1orsource2isnull- Since:
- 2.2
- See Also:
-
mergeDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2, @NonNull @NonNull SingleSource<? extends @NonNull T> source3) Flattens twoSingleSources into oneFlowable, without any transformation, delaying any error(s) until all sources succeed or fail.
You can combine items emitted by multiple
SingleSources so that they appear as oneFlowable, by themergeDelayErrormethod.- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.9 - experimental
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be mergedsource2- aSingleSourceto be mergedsource3- aSingleSourceto be merged- Returns:
- the new
Flowablethat emits all of the items emitted by the sourceSingleSources - Throws:
NullPointerException- ifsource1,source2orsource3isnull- Since:
- 2.2
- See Also:
-
mergeDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2, @NonNull @NonNull SingleSource<? extends @NonNull T> source3, @NonNull @NonNull SingleSource<? extends @NonNull T> source4) Flattens twoSingleSources into oneFlowable, without any transformation, delaying any error(s) until all sources succeed or fail.
You can combine items emitted by multiple
SingleSources so that they appear as oneFlowable, by themergeDelayErrormethod.- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergeDelayErrordoes not operate by default on a particularScheduler.
History: 2.1.9 - experimental
- Type Parameters:
T- the common value type- Parameters:
source1- aSingleSourceto be mergedsource2- aSingleSourceto be mergedsource3- aSingleSourceto be mergedsource4- aSingleSourceto be merged- Returns:
- the new
Flowablethat emits all of the items emitted by the sourceSingleSources - Throws:
NullPointerException- ifsource1,source2,source3orsource4isnull- Since:
- 2.2
- See Also:
-
never
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> never()Returns a singleton instance of a never-signalingSingle(only callsonSubscribe).
- Scheduler:
neverdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the target value type- Returns:
- the singleton never instance
- Since:
- 2.0
-
timer
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public static @NonNull Single<Long> timer(long delay, @NonNull @NonNull TimeUnit unit) Signals success with 0L value after the given delay when aSingleObserversubscribes.
- Scheduler:
timeroperates by default on thecomputationScheduler.
- Parameters:
delay- the delay amountunit- the time unit of the delay- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.0
-
timer
@CheckReturnValue @NonNull @SchedulerSupport("custom") public static @NonNull Single<Long> timer(long delay, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Signals success with 0L value on the specifiedSchedulerafter the given delay when aSingleObserversubscribes.
- Scheduler:
- you specify the
Schedulerto signal on.
- Parameters:
delay- the delay amountunit- the time unit of the delayscheduler- theSchedulerwhere the single 0L will be emitted- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull, or ifschedulerisnull- Since:
- 2.0
-
sequenceEqual
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<Boolean> sequenceEqual(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2) Compares twoSingleSources and emitstrueif they emit the same value (compared viaObject.equals(Object)).
- Scheduler:
sequenceEqualdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value type- Parameters:
source1- the firstSingleSourceinstancesource2- the secondSingleSourceinstance- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsource1orsource2isnull- Since:
- 2.0
-
switchOnNext
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNext(@NonNull @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.
- Backpressure:
- The
sourcesPublisheris consumed in an unbounded manner (requestingLong.MAX_VALUE). The returnedFlowablerespects the backpressure from the downstream. - Scheduler:
switchOnNextdoes not operate by default on a particularScheduler.- Error handling:
- The returned sequence fails with the first error signaled by the
sourcesPublisheror the currently runningSingleSource, disposing the rest. Late errors are forwarded to the global error handler viaRxJavaPlugins.onError(Throwable).
- Type Parameters:
T- the element type of theSingleSources- Parameters:
sources- thePublishersequence of innerSingleSources to switch between- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
- See Also:
-
switchOnNextDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNextDelayError(@NonNull @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.
- Backpressure:
- The
sourcesPublisheris consumed in an unbounded manner (requestingLong.MAX_VALUE). The returnedFlowablerespects the backpressure from the downstream. - Scheduler:
switchOnNextDelayErrordoes not operate by default on a particularScheduler.- Error handling:
- The returned
Flowablecollects all errors emitted by either thesourcesPublisheror any innerSingleSourceand emits them as aCompositeExceptionwhen all sources terminate. If only one source ever failed, its error is emitted as-is at the end.
- Type Parameters:
T- the element type of theSingleSources- Parameters:
sources- thePublishersequence of innerSingleSources to switch between- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifsourcesisnull- Since:
- 3.0.0
- See Also:
-
unsafeCreate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> unsafeCreate(@NonNull @NonNull SingleSource<@NonNull T> onSubscribe) Advanced use only: creates aSingleinstance without any safeguards by using a callback that is called with aSingleObserver.
- Scheduler:
unsafeCreatedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
onSubscribe- the function that is called with the subscribingSingleObserver- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonSubscribeisnullIllegalArgumentException- ifsourceis a subclass ofSingle; such instances don't need conversion and is possibly a port remnant from 1.x or one should usehide()instead.- Since:
- 2.0
-
using
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T, @NonNull U> @NonNull Single<T> using(@NonNull @NonNull Supplier<@NonNull U> resourceSupplier, @NonNull @NonNull Function<? super @NonNull U, ? extends SingleSource<? extends @NonNull T>> sourceSupplier, @NonNull @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).
- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of theSingleSourcegeneratedU- the resource type- Parameters:
resourceSupplier- theSuppliercalled for eachSingleObserverto generate a resource objectsourceSupplier- the function called with the returned resource object fromresourceSupplierand should return aSingleSourceinstance to be run by the operatorresourceCleanup- the consumer of the generated resource that is called exactly once for that particular resource when the generatedSingleSourceterminates (successfully or with an error) or gets disposed.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifresourceSupplier,sourceSupplierandresourceCleanupisnull- Since:
- 2.0
-
using
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull U> @NonNull Single<T> using(@NonNull @NonNull Supplier<@NonNull U> resourceSupplier, @NonNull @NonNull Function<? super @NonNull U, ? extends SingleSource<? extends @NonNull T>> sourceSupplier, @NonNull @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).
- Scheduler:
usingdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type of theSingleSourcegeneratedU- the resource type- Parameters:
resourceSupplier- theSuppliercalled for eachSingleObserverto generate a resource objectsourceSupplier- the function called with the returned resource object fromresourceSupplierand should return aSingleSourceinstance to be run by the operatorresourceCleanup- the consumer of the generated resource that is called exactly once for that particular resource when the generatedSingleSourceterminates (successfully or with an error) or gets disposed.eager- Iftruethen resource disposal will happen either on adispose()call before the upstream is disposed or just before the emission of a terminal event (onSuccessoronError). Iffalsethe resource disposal will happen either on adispose()call after the upstream is disposed or just after the emission of a terminal event (onSuccessoronError).- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifresourceSupplier,sourceSupplierorresourceCleanupisnull- Since:
- 2.0
-
wrap
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> wrap(@NonNull @NonNull SingleSource<@NonNull T> source) Wraps aSingleSourceinstance into a newSingleinstance if not already aSingleinstance.
- Scheduler:
wrapdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the value type- Parameters:
source- the source to wrap- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsourceisnull
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull Iterable<@NonNull ? extends SingleSource<? extends @NonNull T>> sources, @NonNull @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.If the
IterableofSingleSources is empty aNoSuchElementExceptionerror is signaled after subscription.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.
If any of the
SingleSourcessignal an error, all otherSingleSources get disposed and the error emitted to downstream immediately.- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value typeR- the result value type- Parameters:
sources- theIterablesequence ofSingleSourceinstances. An empty sequence will result in anonErrorsignal ofNoSuchElementException.zipper- the function that receives an array with values from eachSingleSourceand should return a value to be emitted to downstream- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifzipperorsourcesisnull- Since:
- 2.0
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2orzipperisnull- See Also:
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeT3- the third sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcesource3- a third sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2,source3orzipperisnull- See Also:
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeT3- the third sourceSingleSource's value typeT4- the fourth sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcesource3- a third sourceSingleSourcesource4- a fourth sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2,source3,source4orzipperisnull- See Also:
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeT3- the third sourceSingleSource's value typeT4- the fourth sourceSingleSource's value typeT5- the fifth sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcesource3- a third sourceSingleSourcesource4- a fourth sourceSingleSourcesource5- a fifth sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2,source3,source4source5orzipperisnull- See Also:
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeT3- the third sourceSingleSource's value typeT4- the fourth sourceSingleSource's value typeT5- the fifth sourceSingleSource's value typeT6- the sixth sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcesource3- a third sourceSingleSourcesource4- a fourth sourceSingleSourcesource5- a fifth sourceSingleSourcesource6- a sixth sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2,source3,source4source5,source6orzipperisnull- See Also:
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull @NonNull SingleSource<? extends @NonNull T7> source7, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeT3- the third sourceSingleSource's value typeT4- the fourth sourceSingleSource's value typeT5- the fifth sourceSingleSource's value typeT6- the sixth sourceSingleSource's value typeT7- the seventh sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcesource3- a third sourceSingleSourcesource4- a fourth sourceSingleSourcesource5- a fifth sourceSingleSourcesource6- a sixth sourceSingleSourcesource7- a seventh sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2,source3,source4source5,source6,source7orzipperisnull- See Also:
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T1, @NonNull T2, @NonNull T3, @NonNull T4, @NonNull T5, @NonNull T6, @NonNull T7, @NonNull T8, @NonNull R> @NonNull Single<R> zip(@NonNull @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull @NonNull SingleSource<? extends @NonNull T7> source7, @NonNull @NonNull SingleSource<? extends @NonNull T8> source8, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeT3- the third sourceSingleSource's value typeT4- the fourth sourceSingleSource's value typeT5- the fifth sourceSingleSource's value typeT6- the sixth sourceSingleSource's value typeT7- the seventh sourceSingleSource's value typeT8- the eighth sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcesource3- a third sourceSingleSourcesource4- a fourth sourceSingleSourcesource5- a fifth sourceSingleSourcesource6- a sixth sourceSingleSourcesource7- a seventh sourceSingleSourcesource8- an eighth sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2,source3,source4source5,source6,source7,source8orzipperisnull- See Also:
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public 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 @NonNull SingleSource<? extends @NonNull T1> source1, @NonNull @NonNull SingleSource<? extends @NonNull T2> source2, @NonNull @NonNull SingleSource<? extends @NonNull T3> source3, @NonNull @NonNull SingleSource<? extends @NonNull T4> source4, @NonNull @NonNull SingleSource<? extends @NonNull T5> source5, @NonNull @NonNull SingleSource<? extends @NonNull T6> source6, @NonNull @NonNull SingleSource<? extends @NonNull T7> source7, @NonNull @NonNull SingleSource<? extends @NonNull T8> source8, @NonNull @NonNull SingleSource<? extends @NonNull T9> source9, @NonNull @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.
- Scheduler:
zipdoes not operate by default on a particularScheduler.
- Type Parameters:
T1- the first sourceSingleSource's value typeT2- the second sourceSingleSource's value typeT3- the third sourceSingleSource's value typeT4- the fourth sourceSingleSource's value typeT5- the fifth sourceSingleSource's value typeT6- the sixth sourceSingleSource's value typeT7- the seventh sourceSingleSource's value typeT8- the eighth sourceSingleSource's value typeT9- the ninth sourceSingleSource's value typeR- the result value type- Parameters:
source1- the first sourceSingleSourcesource2- a second sourceSingleSourcesource3- a third sourceSingleSourcesource4- a fourth sourceSingleSourcesource5- a fifth sourceSingleSourcesource6- a sixth sourceSingleSourcesource7- a seventh sourceSingleSourcesource8- an eighth sourceSingleSourcesource9- a ninth sourceSingleSourcezipper- a function that, when applied to the item emitted by each of the sourceSingleSources, results in an item that will be emitted by the resultingSingle- Returns:
- the new
Singlethat emits the zipped results - Throws:
NullPointerException- ifsource1,source2,source3,source4source5,source6,source7,source8,source9orzipperisnull- See Also:
-
zipArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T, @NonNull R> @NonNull Single<R> zipArray(@NonNull @NonNull Function<? super Object[], ? extends @NonNull R> zipper, @NonNull @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.
If the array of
SingleSources is empty aNoSuchElementExceptionerror is signaled immediately.Note on method signature: since Java doesn't allow creating a generic array with
new T[], the implementation of this operator has to create anObject[]instead. Unfortunately, aFunction<Integer[], R>passed to the method would trigger aClassCastException.If any of the
SingleSources signal an error, all otherSingleSources get disposed and the error emitted to downstream immediately.- Scheduler:
zipArraydoes not operate by default on a particularScheduler.
- Type Parameters:
T- the common value typeR- the result value type- Parameters:
zipper- the function that receives an array with values from eachSingleSourceand should return a value to be emitted to downstreamsources- the array ofSingleSourceinstances. An empty sequence will result in anonErrorsignal ofNoSuchElementException.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifzipperorsourcesisnull- Since:
- 2.0
-
ambWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> ambWith(@NonNull @NonNull SingleSource<? extends @NonNull T> other) Signals the event of this or the otherSingleSourcewhichever signals first.
- Scheduler:
ambWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherSingleSourceto race for the first emission of success or error- Returns:
- the new
Singleinstance. A subscription to this provided source will occur after subscribing to the current source. - Throws:
NullPointerException- ifotherisnull- Since:
- 2.0
-
hide
Hides the identity of the currentSingle, including theDisposablethat is sent to the downstream viaonSubscribe().
- Scheduler:
hidedoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - Since:
- 2.0
-
compose
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Single<R> compose(@NonNull @NonNull SingleTransformer<? super @NonNull T, ? extends @NonNull R> transformer) Transform aSingleby applying a particularSingleTransformerfunction to it.
This method operates on the
Singleitself whereaslift(SingleOperator)operates onSingleObservers.If the operator you are creating is designed to act on the individual item emitted by a
Single, uselift(SingleOperator). If your operator is designed to transform the currentSingleas a whole (for instance, by applying a particular set of existing RxJava operators to it) usecompose.- Scheduler:
composedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the value type of the single returned by the transformer function- Parameters:
transformer- the transformer function, notnull- Returns:
- the new
Singleinstance - Throws:
NullPointerException- iftransformerisnull- See Also:
-
cache
Stores the success value or exception from the currentSingleand replays it to lateSingleObservers.
The returned
Singlesubscribes to the currentSinglewhen the firstSingleObserversubscribes.- Scheduler:
cachedoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - Since:
- 2.0
-
cast
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Single<U> cast(@NonNull @NonNull Class<? extends @NonNull U> clazz) Casts the success value of the currentSingleinto the target type or signals aClassCastExceptionif not compatible.
- Scheduler:
castdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the target type- Parameters:
clazz- the type token to use for casting the success result from the currentSingle- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifclazzisnull- Since:
- 2.0
-
concatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Single<R> concatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns aSinglethat is based on applying a specified function to the item emitted by the currentSingle, where that function returns aSingleSource.
The operator is an alias for
flatMap(Function)- Scheduler:
concatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns aSingleSource- Returns:
- the new
Singlereturned frommapperwhen applied to the item emitted by the currentSingle - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
concatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable concatMapCompletable(@NonNull @NonNull Function<? super @NonNull 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.
The operator is an alias for
flatMapCompletable(Function).- Scheduler:
concatMapCompletabledoes not operate by default on a particularScheduler.
- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns aCompletableSource- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
concatMapMaybe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> concatMapMaybe(@NonNull @NonNull Function<? super @NonNull 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.
The operator is an alias for
flatMapMaybe(Function).- Scheduler:
concatMapMaybedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns aMaybeSource- Returns:
- the new
Maybereturned frommapperwhen applied to the item emitted by the currentSingle - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
concatWith
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> concatWith(@NonNull @NonNull SingleSource<? extends @NonNull T> other) Returns aFlowablethat emits the item emitted by the currentSingle, then the item emitted by the specifiedSingleSource.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
concatWithdoes not operate by default on a particularScheduler.
- Parameters:
other- aSingleSourceto be concatenated after the current- Returns:
- the new
Flowablethat emits the item emitted by the currentSingle, followed by the item emitted byother - Throws:
NullPointerException- ifotherisnull- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> delay(long time, @NonNull @NonNull TimeUnit unit) Delays the emission of the success signal from the currentSingleby the specified amount. An error signal will not be delayed.
- Scheduler:
delayoperates by default on thecomputationScheduler.
- Parameters:
time- the amount of time the success signal should be delayed forunit- the time unit- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.0
- See Also:
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> delay(long time, @NonNull @NonNull TimeUnit unit, boolean delayError) Delays the emission of the success or error signal from the currentSingleby the specified amount.
- Scheduler:
delayoperates by default on thecomputationScheduler.
History: 2.1.5 - experimental
- Parameters:
time- the amount of time the success or error signal should be delayed forunit- the time unitdelayError- iftrue, both success and error signals are delayed. iffalse, only success signals are delayed.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.2
-
delay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Single<T> delay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Delays the emission of the success signal from the currentSingleby the specified amount. An error signal will not be delayed.
- Scheduler:
- you specify the
Schedulerwhere the non-blocking wait and emission happens
- Parameters:
time- the amount of time the success signal should be delayed forunit- the time unitscheduler- the target scheduler to use for the non-blocking wait and emission- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull, or ifschedulerisnull- Since:
- 2.0
- See Also:
-
delay
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> delay(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError) Delays the emission of the success or error signal from the currentSingleby the specified amount.
- Scheduler:
- you specify the
Schedulerwhere the non-blocking wait and emission happens
History: 2.1.5 - experimental
- Parameters:
time- the amount of time the success or error signal should be delayed forunit- the time unitscheduler- the target scheduler to use for the non-blocking wait and emissiondelayError- iftrue, both success and error signals are delayed. iffalse, only success signals are delayed.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull, or ifschedulerisnull- Since:
- 2.2
-
delaySubscription
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> delaySubscription(@NonNull @NonNull CompletableSource subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherCompletableSourcecompletes.
If the delaying source signals an error, that error is re-emitted and no subscription to the current
Singlehappens.- Scheduler:
delaySubscriptiondoes not operate by default on a particularScheduler.
- Parameters:
subscriptionIndicator- theCompletableSourcethat has to complete before the subscription to the currentSinglehappens- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsubscriptionIndicatorisnull- Since:
- 2.0
-
delaySubscription
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Single<T> delaySubscription(@NonNull @NonNull SingleSource<@NonNull U> subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherSingleSourcesignals success.
If the delaying source signals an error, that error is re-emitted and no subscription to the current
Singlehappens.- Scheduler:
delaySubscriptiondoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of the other source- Parameters:
subscriptionIndicator- theSingleSourcethat has to complete before the subscription to the currentSinglehappens- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsubscriptionIndicatorisnull- Since:
- 2.0
-
delaySubscription
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Single<T> delaySubscription(@NonNull @NonNull ObservableSource<@NonNull U> subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherObservableSourcesignals its first value or completes.
If the delaying source signals an error, that error is re-emitted and no subscription to the current
Singlehappens.- Scheduler:
delaySubscriptiondoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of the other source- Parameters:
subscriptionIndicator- theObservableSourcethat has to signal a value or complete before the subscription to the currentSinglehappens- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsubscriptionIndicatorisnull- Since:
- 2.0
-
delaySubscription
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Single<T> delaySubscription(@NonNull @NonNull Flow.Publisher<@NonNull U> subscriptionIndicator) Delays the actual subscription to the currentSingleuntil the given otherFlow.Publishersignals its first value or completes.
If the delaying source signals an error, that error is re-emitted and no subscription to the current
Singlehappens.The other source is consumed in an unbounded manner (requesting
Long.MAX_VALUEfrom it).- Backpressure:
- The
otherpublisher is consumed in an unbounded fashion but will be cancelled after the first item it produced. - Scheduler:
delaySubscriptiondoes not operate by default on a particularScheduler.
- Type Parameters:
U- the element type of the other source- Parameters:
subscriptionIndicator- thePublisherthat has to signal a value or complete before the subscription to the currentSinglehappens- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifsubscriptionIndicatorisnull- Since:
- 2.0
-
delaySubscription
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> delaySubscription(long time, @NonNull @NonNull TimeUnit unit) Delays the actual subscription to the currentSingleuntil the given time delay elapsed.
- Scheduler:
delaySubscriptiondoes by default subscribe to the currentSingleon thecomputationSchedulerafter the delay.
- Parameters:
time- the time amount to wait with the subscriptionunit- the time unit of the waiting- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.0
-
delaySubscription
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Single<T> delaySubscription(long time, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Delays the actual subscription to the currentSingleuntil the given time delay elapsed.
- Scheduler:
delaySubscriptiondoes by default subscribe to the currentSingleon theScheduleryou provided, after the delay.
- Parameters:
time- the time amount to wait with the subscriptionunit- the time unit of the waitingscheduler- theSchedulerto wait on and subscribe on to the currentSingle- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 2.0
-
dematerialize
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> dematerialize(@NonNull @NonNull Function<? super @NonNull T, @NonNull Notification<@NonNull R>> selector) Maps theNotificationsuccess value of the currentSingleback into normalonSuccess,onErrororonCompletesignals as aMaybesource.
The intended use of the
selectorfunction is to perform a type-safe identity mapping (see example) on a source that is already of typeNotification<T>. The Java language doesn't allow limiting instance methods to a certain generic argument shape, therefore, a function is used to ensure the conversion remains type safe.- Scheduler:
dematerializedoes not operate by default on a particularScheduler.
Example:
Single.just(Notification.createOnNext(1)) .dematerialize(notification -> notification) .test() .assertResult(1);History: 2.2.4 - experimental
- Type Parameters:
R- the result type- Parameters:
selector- the function called with the success item and should return aNotificationinstance.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifselectorisnull- Since:
- 3.0.0
- See Also:
-
doAfterSuccess
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doAfterSuccess(@NonNull @NonNull Consumer<? super @NonNull T> onAfterSuccess) Calls the specified consumer with the success item after this item has been emitted to the downstream.
Note that the
doAfterSuccessaction is shared between subscriptions and as such should be thread-safe.- Scheduler:
doAfterSuccessdoes not operate by default on a particularScheduler.
History: 2.0.1 - experimental
- Parameters:
onAfterSuccess- theConsumerthat will be called after emitting an item from upstream to the downstream- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonAfterSuccessisnull- Since:
- 2.1
-
doAfterTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doAfterTerminate(@NonNull @NonNull Action onAfterTerminate) Registers anActionto be called after thisSingleinvokes eitheronSuccessoronError.
Note that the
doAfterTerminateaction is shared between subscriptions and as such should be thread-safe.- Scheduler:
doAfterTerminatedoes not operate by default on a particularScheduler.
History: 2.0.6 - experimental
- Parameters:
onAfterTerminate- anActionto be invoked when the currentSinglefinishes- Returns:
- the new
Singlethat emits the same items as the currentSingle, then invokes theAction - Throws:
NullPointerException- ifonAfterTerminateisnull- Since:
- 2.1
- See Also:
-
doFinally
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doFinally(@NonNull @NonNull Action onFinally) Calls the specified action after thisSinglesignalsonSuccessoronErroror gets disposed by the downstream.In case of a race between a terminal event and a dispose call, the provided
onFinallyaction is executed once per subscription.Note that the
onFinallyaction is shared between subscriptions and as such should be thread-safe.
- Scheduler:
doFinallydoes not operate by default on a particularScheduler.
History: 2.0.1 - experimental
- Parameters:
onFinally- the action called when thisSingleterminates or gets disposed- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonFinallyisnull- Since:
- 2.1
-
doOnLifecycle
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> doOnLifecycle(@NonNull @NonNull Consumer<? super Disposable> onSubscribe, @NonNull @NonNull Action onDispose) Calls the appropriateonXXXmethod (shared between allSingleObservers) for the lifecycle events of the sequence (subscription, disposal).
- Scheduler:
doOnLifecycledoes not operate by default on a particularScheduler.
- Parameters:
onSubscribe- aConsumercalled with theDisposablesent viaSingleObserver.onSubscribe(Disposable)onDispose- called when the downstream disposes theDisposableviadispose()- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonSubscribeoronDisposeisnull- Since:
- 3.0.0
- See Also:
-
doOnSubscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnSubscribe(@NonNull @NonNull Consumer<? super Disposable> onSubscribe) Calls the shared consumer with theDisposablesent through theonSubscribefor eachSingleObserverthat subscribes to the currentSingle.
- Scheduler:
doOnSubscribedoes not operate by default on a particularScheduler.
- Parameters:
onSubscribe- the consumer called with theDisposablesent viaonSubscribe- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonSubscribeisnull- Since:
- 2.0
-
doOnTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnTerminate(@NonNull @NonNull Action onTerminate) Returns aSingleinstance that calls the givenonTerminatecallback just before thisSinglecompletes normally or with an exception.
This differs from
doAfterTerminatein that this happens before theonSuccessoronErrornotification.- Scheduler:
doOnTerminatedoes not operate by default on a particularScheduler.
History: 2.2.7 - experimental
- Parameters:
onTerminate- the action to invoke when the consumer callsonSuccessoronError- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonTerminateisnull- Since:
- 3.0.0
- See Also:
-
doOnSuccess
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnSuccess(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess) Calls the shared consumer with the success value sent viaonSuccessfor eachSingleObserverthat subscribes to the currentSingle.
- Scheduler:
doOnSuccessdoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- the consumer called with the success value ofonSuccess- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonSuccessisnull- Since:
- 2.0
-
doOnEvent
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnEvent(@NonNull @NonNull BiConsumer<@Nullable ? super @NonNull T, @Nullable ? super Throwable> onEvent) Calls the shared consumer with the error sent viaonErroror the value viaonSuccessfor eachSingleObserverthat subscribes to the currentSingle.
- Scheduler:
doOnEventdoes not operate by default on a particularScheduler.
- Parameters:
onEvent- the consumer called with the success value of onEvent- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonEventisnull- Since:
- 2.0
-
doOnError
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnError(@NonNull @NonNull Consumer<? super Throwable> onError) Calls the shared consumer with the error sent viaonErrorfor eachSingleObserverthat subscribes to the currentSingle.
- Scheduler:
doOnErrordoes not operate by default on a particularScheduler.
- Parameters:
onError- the consumer called with the success value ofonError- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonErrorisnull- Since:
- 2.0
-
doOnDispose
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnDispose(@NonNull @NonNull Action onDispose) Calls the sharedActionif aSingleObserversubscribed to the currentSingledisposes the commonDisposableit received viaonSubscribe.
- Scheduler:
doOnDisposedoes not operate by default on a particularScheduler.
- Parameters:
onDispose- the action called when the subscription is disposed- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonDisposeisnull- Since:
- 2.0
-
filter
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> filter(@NonNull @NonNull Predicate<? super @NonNull T> predicate) Filters the success item of theSinglevia a predicate function and emitting it if the predicate returnstrue, completing otherwise.
- Scheduler:
filterdoes not operate by default on a particularScheduler.
- Parameters:
predicate- a function that evaluates the item emitted by the currentSingle, returningtrueif it passes the filter- Returns:
- the new
Maybethat emit the item emitted by the currentSinglethat the filter evaluates astrue - Throws:
NullPointerException- ifpredicateisnull- See Also:
-
flatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Single<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> mapper) Returns aSinglethat is based on applying a specified function to the item emitted by the currentSingle, where that function returns aSingleSource.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns aSingleSource- Returns:
- the new
Singlereturned frommapperwhen applied to the item emitted by the currentSingle - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U, @NonNull R> @NonNull Single<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull U>> mapper, @NonNull @NonNull BiFunction<? super @NonNull 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.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by theSingleSourcereturned by themapperfunctionR- the type of items emitted by the resultingSingle- Parameters:
mapper- a function that returns aSingleSourcefor the item emitted by the currentSinglecombiner- a function that combines one item emitted by each of the source and collectionSingleSourceand returns an item to be emitted by the resultingSingleSource- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifmapperorcombinerisnull- Since:
- 3.0.0
- See Also:
-
flatMap
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Single<R> flatMap(@NonNull @NonNull Function<? super @NonNull T, ? extends SingleSource<? extends @NonNull R>> onSuccessMapper, @NonNull @NonNull Function<? super Throwable, ? extends SingleSource<? extends @NonNull R>> onErrorMapper) Maps theonSuccessoronErrorsignals of the currentSingleinto aSingleSourceand emits thatSingleSource's signals.
- Scheduler:
flatMapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result type- Parameters:
onSuccessMapper- a function that returns aSingleSourceto merge for theonSuccessitem emitted by thisSingleonErrorMapper- a function that returns aSingleSourceto merge for anonErrornotification from thisSingle- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifonSuccessMapperoronErrorMapperisnull- Since:
- 3.0.0
- See Also:
-
flatMapMaybe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Maybe<R> flatMapMaybe(@NonNull @NonNull Function<? super @NonNull 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.
- Scheduler:
flatMapMaybedoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns aMaybeSource- Returns:
- the new
Maybereturned frommapperwhen applied to the item emitted by the currentSingle - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMapPublisher
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Flowable<R> flatMapPublisher(@NonNull @NonNull Function<? super @NonNull 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.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer and thePublisherreturned by the mapper function is expected to honor it as well. - Scheduler:
flatMapPublisherdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns aPublisher- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flattenAsFlowable
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Flowable<U> flattenAsFlowable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Maps the success value of the currentSingleinto anIterableand emits its items as aFlowablesequence.
- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
flattenAsFlowabledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of item emitted by the resultingIterable- Parameters:
mapper- a function that returns anIterablesequence of values for when given an item emitted by the currentSingle- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flattenAsObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Observable<U> flattenAsObservable(@NonNull @NonNull Function<@NonNull ? super @NonNull T, @NonNull ? extends Iterable<? extends @NonNull U>> mapper) Maps the success value of the currentSingleinto anIterableand emits its items as anObservablesequence.
- Scheduler:
flattenAsObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of item emitted by the resultingIterable- Parameters:
mapper- a function that returns anIterablesequence of values for when given an item emitted by the currentSingle- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMapObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Observable<R> flatMapObservable(@NonNull @NonNull Function<? super @NonNull 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.
- Scheduler:
flatMapObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns anObservableSource- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- See Also:
-
flatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable flatMapCompletable(@NonNull @NonNull Function<? super @NonNull 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.
- Scheduler:
flatMapCompletabledoes not operate by default on a particularScheduler.
- Parameters:
mapper- a function that, when applied to the item emitted by the currentSingle, returns aCompletableSource- Returns:
- the new
Completableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 2.0
- See Also:
-
blockingGet
Waits in a blocking fashion until the currentSinglesignals a success value (which is returned) or an exception (which is propagated).
- Scheduler:
blockingGetdoes not operate by default on a particularScheduler.- Error handling:
- If the source signals an error, the operator wraps a checked
ExceptionintoRuntimeExceptionand throws that. Otherwise,RuntimeExceptions andErrors are rethrown as they are.
- Returns:
- the success value
-
blockingSubscribe
Subscribes to the currentSingleand blocks the current thread until it terminates.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- If the current
Singlesignals an error, theThrowableis routed to the global error handler viaRxJavaPlugins.onError(Throwable). If the current thread is interrupted, anInterruptedExceptionis routed to the same global error handler.
- Since:
- 3.0.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess) Subscribes to the currentSingleand calls givenonSuccesscallback on the current thread when it completes normally.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- If either the current
Singlesignals an error oronSuccessthrows, the respectiveThrowableis routed to the global error handler viaRxJavaPlugins.onError(Throwable). If the current thread is interrupted, anInterruptedExceptionis routed to the same global error handler.
- Parameters:
onSuccess- theConsumerto call if the currentSinglesucceeds- Throws:
NullPointerException- ifonSuccessisnull- Since:
- 3.0.0
- See Also:
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError) Subscribes to the currentSingleand calls the appropriate callback on the current thread when it terminates.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- If either
onSuccessoronErrorthrow, theThrowableis routed to the global error handler viaRxJavaPlugins.onError(Throwable). If the current thread is interrupted, theonErrorconsumer is called with anInterruptedException.
- Parameters:
onSuccess- theConsumerto call if the currentSinglesucceedsonError- theConsumerto call if the currentSinglesignals an error- Throws:
NullPointerException- ifonSuccessoronErrorisnull- Since:
- 3.0.0
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull SingleObserver<? super @NonNull T> observer) Subscribes to the currentSingleand calls the appropriateSingleObservermethod on the current thread.
- Scheduler:
blockingSubscribedoes not operate by default on a particularScheduler.- Error handling:
- An
onErrorsignal is delivered to theSingleObserver.onError(Throwable)method. If any of theSingleObserver's methods throw, theRuntimeExceptionis propagated to the caller of this method. If the current thread is interrupted, anInterruptedExceptionis delivered toobserver.onError.
- Parameters:
observer- theSingleObserverto call methods on the current thread- Throws:
NullPointerException- ifobserverisnull- Since:
- 3.0.0
-
lift
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Single<R> lift(@NonNull @NonNull SingleOperator<? extends @NonNull R, ? super @NonNull 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.
Generally, such a new
SingleObserverwill wrap the downstream'sSingleObserverand forwards theonSuccessandonErrorevents from the upstream directly or according to the emission pattern the custom operator's business logic requires. In addition, such operator can intercept the flow control calls ofdisposeandisDisposedthat would have traveled upstream and perform additional actions depending on the same business logic requirements.Example:
// Step 1: Create the consumer type that will be returned by the SingleOperator.apply(): public final class CustomSingleObserver<T> implements SingleObserver<T>, Disposable { // The downstream's SingleObserver that will receive the onXXX events final SingleObserver<? super String> downstream; // The connection to the upstream source that will call this class' onXXX methods Disposable upstream; // The constructor takes the downstream subscriber and usually any other parameters public CustomSingleObserver(SingleObserver<? super String> downstream) { this.downstream = downstream; } // In the subscription phase, the upstream sends a Disposable to this class // and subsequently this class has to send a Disposable to the downstream. // Note that relaying the upstream's Disposable directly is not allowed in RxJava @Override public void onSubscribe(Disposable d) { if (upstream != null) { d.dispose(); } else { upstream = d; downstream.onSubscribe(this); } } // The upstream calls this with the next item and the implementation's // responsibility is to emit an item to the downstream based on the intended // business logic, or if it can't do so for the particular item, // request more from the upstream @Override public void onSuccess(T item) { String str = item.toString(); if (str.length() < 2) { downstream.onSuccess(str); } else { // Single is usually expected to produce one of the onXXX events downstream.onError(new NoSuchElementException()); } } // Some operators may handle the upstream's error while others // could just forward it to the downstream. @Override public void onError(Throwable throwable) { downstream.onError(throwable); } // Some operators may use their own resources which should be cleaned up if // the downstream disposes the flow before it completed. Operators without // resources can simply forward the dispose to the upstream. // In some cases, a disposed flag may be set by this method so that other parts // of this class may detect the dispose and stop sending events // to the downstream. @Override public void dispose() { upstream.dispose(); } // Some operators may simply forward the call to the upstream while others // can return the disposed flag set in dispose(). @Override public boolean isDisposed() { return upstream.isDisposed(); } } // Step 2: Create a class that implements the SingleOperator interface and // returns the custom consumer type from above in its apply() method. // Such class may define additional parameters to be submitted to // the custom consumer type. final class CustomSingleOperator<T> implements SingleOperator<String> { @Override public SingleObserver<? super String> apply(SingleObserver<? super T> upstream) { return new CustomSingleObserver<T>(upstream); } } // Step 3: Apply the custom operator via lift() in a flow by creating an instance of it // or reusing an existing one. Single.just(5) .lift(new CustomSingleOperator<Integer>()) .test() .assertResult("5"); Single.just(15) .lift(new CustomSingleOperator<Integer>()) .test() .assertFailure(NoSuchElementException.class);Creating custom operators can be complicated and it is recommended one consults the RxJava wiki: Writing operators page about the tools, requirements, rules, considerations and pitfalls of implementing them.
Note that implementing custom operators via this
lift()method adds slightly more overhead by requiring an additional allocation and indirection per assembled flows. Instead, extending the abstractSingleclass and creating aSingleTransformerwith it is recommended.Note also that it is not possible to stop the subscription phase in
lift()as theapply()method requires a non-nullSingleObserverinstance to be returned, which is then unconditionally subscribed to the currentSingle. For example, if the operator decided there is no reason to subscribe to the upstream source because of some optimization possibility or a failure to prepare the operator, it still has to return aSingleObserverthat should immediately dispose the upstream'sDisposablein itsonSubscribemethod. Again, using aSingleTransformerand extending theSingleis a better option assubscribeActual(SingleObserver)can decide to not subscribe to its upstream after all.- Scheduler:
liftdoes not operate by default on a particularScheduler, however, theSingleOperatormay use aSchedulerto support its own asynchronous behavior.
- Type Parameters:
R- the output value type- Parameters:
lift- theSingleOperatorthat receives the downstream'sSingleObserverand should return aSingleObserverwith custom behavior to be used as the consumer for the currentSingle.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifliftisnull- See Also:
-
map
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Single<R> map(@NonNull @NonNull Function<? super @NonNull T, ? extends @NonNull R> mapper) Returns aSinglethat applies a specified function to the item emitted by the currentSingleand emits the result of this function application.
- Scheduler:
mapdoes not operate by default on a particularScheduler.
- Type Parameters:
R- the result value type- Parameters:
mapper- a function to apply to the item emitted by theSingle- Returns:
- the new
Singlethat emits the item from the currentSingle, transformed by the specified function - Throws:
NullPointerException- ifmapperisnull- See Also:
-
materialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Notification<T>> materialize()Maps the signal types of thisSingleinto aNotificationof the same kind and emits it as a single success value to downstream.
- Scheduler:
materializedoes not operate by default on a particularScheduler.
History: 2.2.4 - experimental
- Returns:
- the new
Singleinstance - Since:
- 3.0.0
- See Also:
-
contains
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Boolean> contains(@NonNull @NonNull Object item) Signalstrueif the currentSinglesignals a success value that isObject.equals(Object)with the value provided.
- Scheduler:
containsdoes not operate by default on a particularScheduler.
- Parameters:
item- the value to compare against the success value of thisSingle- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifitemisnull- Since:
- 2.0
-
contains
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<Boolean> contains(@NonNull @NonNull Object item, @NonNull @NonNull BiPredicate<Object, Object> comparer) Signalstrueif the currentSinglesignals a success value that is equal with the value provided by calling aBiPredicate.
- Scheduler:
containsdoes not operate by default on a particularScheduler.
- Parameters:
item- the value to compare against the success value of thisSinglecomparer- the function that receives the success value of thisSingle, the value provided and should returntrueif they are considered equal- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifitemorcomparerisnull- Since:
- 2.0
-
mergeWith
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> mergeWith(@NonNull @NonNull SingleSource<? extends @NonNull T> other) Flattens thisSingleand anotherSingleSourceinto oneFlowable, without any transformation.
You can combine items emitted by multiple
SingleSources so that they appear as oneFlowable, by using themergeWithmethod.- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
mergeWithdoes not operate by default on a particularScheduler.
- Parameters:
other- aSingleSourceto be merged- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- See Also:
-
ofType
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<U> ofType(@NonNull @NonNull Class<@NonNull U> clazz) Filters the items emitted by the currentSingle, only emitting its success value if that is an instance of the suppliedClass.
- Scheduler:
ofTypedoes not operate by default on a particularScheduler.
- Type Parameters:
U- the output type- Parameters:
clazz- the class type to filter the items emitted by the currentSingle- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifclazzisnull- Since:
- 3.0.0
- See Also:
-
observeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> observeOn(@NonNull @NonNull Scheduler scheduler) Signals the success item or the terminal signals of the currentSingleon the specifiedScheduler, asynchronously.
- Scheduler:
- you specify which
Schedulerthis operator will use.
- Parameters:
scheduler- theSchedulerto notify subscribers on- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
onErrorReturn
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> onErrorReturn(@NonNull @NonNull Function<Throwable, ? extends @NonNull T> itemSupplier) Ends the flow with a success item returned by a function for theThrowableerror signaled by the currentSingleinstead of signaling the error viaonError.
By default, when a
Singleencounters an error that prevents it from emitting the expected item to its subscriber, theSingleinvokes its subscriber'sSingleObserver.onError(Throwable)method, and then quits without invoking any more of its observer's methods. TheonErrorReturnmethod changes this behavior. If you pass a function (resumeFunction) to aSingle'sonErrorReturnmethod, if the originalSingleencounters an error, instead of invoking its observer'sSingleObserver.onError(Throwable)method, it will instead emit the return value ofresumeFunction.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorReturndoes not operate by default on a particularScheduler.
- Parameters:
itemSupplier- a function that returns an item that the newSinglewill emit if the currentSingleencounters an error- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifitemSupplierisnull- See Also:
-
onErrorReturnItem
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> onErrorReturnItem(@NonNull @NonNull T item) Signals the specified value as success in case the currentSinglesignals an error.
- Scheduler:
onErrorReturnItemdoes not operate by default on a particularScheduler.
- Parameters:
item- the value to signal if the currentSinglefails- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifitemisnull- Since:
- 2.0
-
onErrorResumeWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> onErrorResumeWith(@NonNull @NonNull SingleSource<? extends @NonNull T> fallback) Resumes the flow with the givenSingleSourcewhen the currentSinglefails instead of signaling the error viaonError.
By default, when a
Singleencounters an error that prevents it from emitting the expected item to itsSingleObserver, theSingleinvokes itsSingleObserver'sonErrormethod, and then quits without invoking any more of itsSingleObserver's methods. TheonErrorResumeWithmethod changes this behavior. If you pass anotherSingle(resumeSingleInCaseOfError) to aSingle'sonErrorResumeWithmethod, if the originalSingleencounters an error, instead of invoking itsSingleObserver'sonErrormethod, it will instead relinquish control toresumeSingleInCaseOfErrorwhich will invoke theSingleObserver'sonSuccessmethod if it is able to do so. In such a case, because noSinglenecessarily invokesonError, theSingleObservermay never know that an error happened.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorResumeWithdoes not operate by default on a particularScheduler.
- Parameters:
fallback- aSinglethat will take control if sourceSingleencounters an error.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- iffallbackisnull- See Also:
-
onErrorComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> onErrorComplete()Returns aMaybeinstance that if the currentSingleemits an error, it will emit anonCompleteand swallow the throwable.
- Scheduler:
onErrorCompletedoes not operate by default on a particularScheduler.
- Returns:
- the new
Maybeinstance - Since:
- 3.0.0
-
onErrorComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorComplete(@NonNull @NonNull Predicate<? super Throwable> predicate) Returns aMaybeinstance that if thisSingleemits an error and the predicate returnstrue, it will emit anonCompleteand swallow the throwable.
- Scheduler:
onErrorCompletedoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate to call when anThrowableis emitted which should returntrueif theThrowableshould be swallowed and replaced with anonComplete.- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifpredicateisnull- Since:
- 3.0.0
-
onErrorResumeNext
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> onErrorResumeNext(@NonNull @NonNull Function<? super Throwable, ? extends SingleSource<? extends @NonNull T>> fallbackSupplier) Resumes the flow with aSingleSourcereturned for the failureThrowableof the currentSingleby a function instead of signaling the error viaonError.
By default, when a
Singleencounters an error that prevents it from emitting the expected item to itsSingleObserver, theSingleinvokes itsSingleObserver'sonErrormethod, and then quits without invoking any more of itsSingleObserver's methods. TheonErrorResumeNextmethod changes this behavior. If you pass a function that will return anotherSingle(resumeFunctionInCaseOfError) to aSingle'sonErrorResumeNextmethod, if the originalSingleencounters an error, instead of invoking itsSingleObserver'sonErrormethod, it will instead relinquish control toresumeSingleInCaseOfErrorwhich will invoke theSingleObserver'sonSuccessmethod if it is able to do so. In such a case, because noSinglenecessarily invokesonError, theSingleObservermay never know that an error happened.You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
- Scheduler:
onErrorResumeNextdoes not operate by default on a particularScheduler.
- Parameters:
fallbackSupplier- a function that returns aSingleSourcethat will take control if sourceSingleencounters an error.- Returns:
- the new
Singleinstance - Throws:
NullPointerException- iffallbackSupplierisnull- Since:
- .20
- See Also:
-
onTerminateDetach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> onTerminateDetach()Nulls out references to the upstream producer and downstreamSingleObserverif the sequence is terminated or downstream callsdispose().
- Scheduler:
onTerminateDetachdoes not operate by default on a particularScheduler.
History: 2.1.5 - experimental
- Returns:
- the new
Singlewhichnulls out references to the upstream producer and downstreamSingleObserverif the sequence is terminated or downstream callsdispose() - Since:
- 2.2
-
repeat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeat()Repeatedly re-subscribes to the currentSingleand emits each success value as aFlowablesequence.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
repeatdoes not operate by default on a particularScheduler.
- Returns:
- the new
Flowableinstance - Since:
- 2.0
-
repeat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeat(long times) Re-subscribes to the currentSingleat most the given number of times and emits each success value as aFlowablesequence.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
repeatdoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times to re-subscribe to the currentSingle- Returns:
- the new
Flowableinstance - Throws:
IllegalArgumentException- iftimesis negative- Since:
- 2.0
-
repeatWhen
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatWhen(@NonNull @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.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. ThePublisherreturned by the handler function is expected to honor backpressure as well. - Scheduler:
repeatWhendoes not operate by default on a particularScheduler.
- Parameters:
handler- the function that is called with aFlowablethat signals a value when theSinglesignaled a success value and returns aPublisherthat has to signal a value to trigger a resubscription to the currentSingle, otherwise the terminal signal of thePublisherwill be the terminal signal of the sequence as well.- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifhandlerisnull- Since:
- 2.0
-
repeatUntil
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatUntil(@NonNull @NonNull BooleanSupplier stop) Re-subscribes to the currentSingleuntil the givenBooleanSupplierreturnstrueand emits the success items as aFlowablesequence.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
repeatUntildoes not operate by default on a particularScheduler.
- Parameters:
stop- theBooleanSuppliercalled after the currentSinglesucceeds and if returnsfalse, theSingleis re-subscribed; otherwise the sequence completes.- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifstopisnull- Since:
- 2.0
-
retry
Repeatedly re-subscribes to the currentSingleindefinitely if it fails with anonError.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Returns:
- the new
Singleinstance - Since:
- 2.0
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry(long times) Repeatedly re-subscribe at most the specified times to the currentSingleif it fails with anonError.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
times- the number of times to resubscribe if the currentSinglefails- Returns:
- the new
Singleinstance - Throws:
IllegalArgumentException- iftimesis negative- Since:
- 2.0
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry(@NonNull @NonNull BiPredicate<? super Integer, ? super Throwable> predicate) Re-subscribe to the currentSingleif the given predicate returnstruewhen theSinglefails with anonError.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate called with the resubscription count and the failureThrowableand should returntrueif a resubscription should happen- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifpredicateisnull- Since:
- 2.0
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry(long times, @NonNull @NonNull Predicate<? super Throwable> predicate) Repeatedly re-subscribe at most times or until the predicate returnsfalse, whichever happens first if it fails with anonError.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
History: 2.1.8 - experimental
- Parameters:
times- the number of times to resubscribe if the currentSinglefailspredicate- the predicate called with the failureThrowableand should returntrueif a resubscription should happen- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifpredicateisnullIllegalArgumentException- iftimesis negative- Since:
- 2.2
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry(@NonNull @NonNull Predicate<? super Throwable> predicate) Re-subscribe to the currentSingleif the given predicate returnstruewhen theSinglefails with anonError.
- Scheduler:
retrydoes not operate by default on a particularScheduler.
- Parameters:
predicate- the predicate called with the failureThrowableand should returntrueif a resubscription should happen- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifpredicateisnull- Since:
- 2.0
-
retryUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> retryUntil(@NonNull @NonNull BooleanSupplier stop) Retries until the given stop function returnstrue.
- Scheduler:
retryUntildoes not operate by default on a particularScheduler.
- Parameters:
stop- the function that should returntrueto stop retrying- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifstopisnull- Since:
- 3.0.0
-
retryWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retryWhen(@NonNull @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.
If the
Publishersignals anonComplete, the resultingSinglewill signal aNoSuchElementException.Note that the inner
Publisherreturned by the handler function should signal eitheronNext,onErrororonCompletein response to the receivedThrowableto indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signalingonNextfollowed byonCompleteimmediately may result in the sequence to be completed immediately. Similarly, if this innerPublishersignalsonErrororonCompletewhile the upstream is active, the sequence is terminated with the same signal immediately.The following example demonstrates how to retry an asynchronous source with a delay:
Single.timer(1, TimeUnit.SECONDS) .doOnSubscribe(s -> System.out.println("subscribing")) .map(v -> { throw new RuntimeException(); }) .retryWhen(errors -> { AtomicInteger counter = new AtomicInteger(); return errors .takeWhile(e -> counter.getAndIncrement() != 3) .flatMap(e -> { System.out.println("delay retry by " + counter.get() + " second(s)"); return Flowable.timer(counter.get(), TimeUnit.SECONDS); }); }) .blockingGet();- Scheduler:
retryWhendoes not operate by default on a particularScheduler.
- Parameters:
handler- the function that receives aFlowableof the error theSingleemits and should return aPublisherthat should signal a normal value (in response to the throwable theFlowableemits) to trigger a resubscription or signal an error to be the output of the resultingSingle- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifhandlerisnull
-
safeSubscribe
@SchedulerSupport("none") public final void safeSubscribe(@NonNull @NonNull SingleObserver<? super @NonNull 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).By default, the
Singleprotocol forbids theonXXXmethods to throw, but someSingleObserverimplementation may do it anyway, causing undefined behavior in the upstream. This method and the underlying safe wrapper ensures such misbehaving consumers don't disrupt the protocol.- Scheduler:
safeSubscribedoes not operate by default on a particularScheduler.
- Parameters:
observer- the potentially misbehavingSingleObserver- Throws:
NullPointerException- ifobserverisnull- Since:
- 3.0.0
- See Also:
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull CompletableSource other) Returns aFlowablewhich first runs the otherCompletableSourcethen the currentSingleif the other completed normally.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherCompletableSourceto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull SingleSource<@NonNull T> other) Returns aFlowablewhich first runs the otherSingleSourcethen the currentSingleif the other succeeded normally.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherSingleSourceto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull MaybeSource<@NonNull T> other) Returns aFlowablewhich first runs the otherMaybeSourcethen the currentSingleif the other succeeded or completed normally.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherMaybeSourceto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> startWith(@NonNull @NonNull ObservableSource<@NonNull T> other) Returns anObservablewhich first delivers the events of the otherObservableSourcethen runs the currentSingle.
- Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherObservableSourceto run first- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public final @NonNull Flowable<T> startWith(@NonNull @NonNull Flow.Publisher<@NonNull T> other) Returns aFlowablewhich first delivers the events of the otherFlow.Publisherthen runs the currentSingle.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer and expects the otherPublisherto honor it as well. - Scheduler:
startWithdoes not operate by default on a particularScheduler.
- Parameters:
other- the otherPublisherto run first- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifotherisnull- Since:
- 3.0.0
-
subscribe
Subscribes to aSinglebut ignore its emission or notification.
If the
Singleemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - See Also:
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull BiConsumer<@Nullable ? super @NonNull T, @Nullable ? super Throwable> onCallback) Subscribes to aSingleand provides a composite callback to handle the item it emits or any error notification it issues.
- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onCallback- the callback that receives either the success value or the failureThrowable(whichever is notnull)- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - Throws:
NullPointerException- ifonCallbackisnull- See Also:
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess) Subscribes to aSingleand provides a callback to handle the item it emits.
If the
Singleemits an error, it is wrapped into anOnErrorNotImplementedExceptionand routed to theRxJavaPlugins.onError(Throwable)handler.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theConsumer<T>you have designed to accept the emission from theSingle- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - Throws:
NullPointerException- ifonSuccessisnull- See Also:
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError) Subscribes to aSingleand provides callbacks to handle the item it emits or any error notification it issues.
- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- theConsumer<T>you have designed to accept the emission from theSingleonError- theConsumer<Throwable>you have designed to accept any error notification from theSingle- Returns:
- the new
Disposableinstance that can be used for disposing the subscription at any time - Throws:
NullPointerException- ifonSuccessoronErrorisnull- See Also:
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super Throwable> onError, @NonNull @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.The
SingleObserverwill be removed after the callback for the terminal event has been invoked.- Scheduler:
subscribedoes not operate by default on a particularScheduler.
- Parameters:
onSuccess- the callback for upstream itemsonError- the callback for an upstream error if anycontainer- theDisposableContainer(such asCompositeDisposable) to add and remove the createdDisposableSingleObserver- Returns:
- the
Disposablethat allows disposing the particular subscription. - Throws:
NullPointerException- ifonSuccess,onErrororcontainerisnull- Since:
- 3.1.0
-
subscribe
@SchedulerSupport("none") public final void subscribe(@NonNull @NonNull SingleObserver<? super @NonNull T> observer) Description copied from interface:SingleSourceSubscribes the givenSingleObserverto thisSingleSourceinstance.- Specified by:
subscribein interfaceSingleSource<T>- Parameters:
observer- theSingleObserver, notnull
-
subscribeActual
protected abstract void subscribeActual(@NonNull @NonNull SingleObserver<? super @NonNull T> observer) Implement 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 bysubscribe(SingleObserver)before this method gets called.- Parameters:
observer- theSingleObserverto handle, notnull
-
subscribeWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull E extends SingleObserver<? super @NonNull T>> E subscribeWith(@NonNull E observer) Subscribes a givenSingleObserver(subclass) to thisSingleand returns the givenSingleObserveras is.
Usage example:
Single<Integer> source = Single.just(1); CompositeDisposable composite = new CompositeDisposable(); DisposableSingleObserver<Integer> ds = new DisposableSingleObserver<>() { // ... }; composite.add(source.subscribeWith(ds));- Scheduler:
subscribeWithdoes not operate by default on a particularScheduler.
- Type Parameters:
E- the type of theSingleObserverto use and return- Parameters:
observer- theSingleObserver(subclass) to use and return, notnull- Returns:
- the input
observer - Throws:
NullPointerException- ifobserverisnull- Since:
- 2.0
-
subscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> subscribeOn(@NonNull @NonNull Scheduler scheduler) Asynchronously subscribesSingleObservers to thisSingleon the specifiedScheduler.
- Scheduler:
- You specify which
Schedulerthis operator will use.
- Parameters:
scheduler- theSchedulerto perform subscription actions on- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifschedulerisnull- See Also:
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<Timed<T>> timeInterval()Measures the time (in milliseconds) between the subscription and success item emission of the currentSingleand signals it as a tuple (Timed) success value.
If the current
Singlefails, the resultingSinglewill pass along the signal to the downstream. To measure the time to error, usematerialize()and applytimeInterval().- Scheduler:
timeIntervaluses thecomputationSchedulerfor determining the current time upon subscription and upon receiving the success item from the currentSingle.
- Returns:
- the new
Singleinstance - Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<Timed<T>> timeInterval(@NonNull @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.
If the current
Singlefails, the resultingSinglewill pass along the signal to the downstream. To measure the time to error, usematerialize()and applytimeInterval(Scheduler).- Scheduler:
timeIntervaluses the providedSchedulerfor determining the current time upon subscription and upon receiving the success item from the currentSingle.
- Parameters:
scheduler- theSchedulerused for providing the current time- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifschedulerisnull- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<Timed<T>> timeInterval(@NonNull @NonNull TimeUnit unit) Measures the time between the subscription and success item emission of the currentSingleand signals it as a tuple (Timed) success value.
If the current
Singlefails, the resultingSinglewill pass along the signals to the downstream. To measure the time to error, usematerialize()and applytimeInterval(TimeUnit, Scheduler).- Scheduler:
timeIntervaluses thecomputationSchedulerfor determining the current time upon subscription and upon receiving the success item from the currentSingle.
- Parameters:
unit- the time unit for measurement- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<Timed<T>> timeInterval(@NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Measures the time between the subscription and success item emission of the currentSingleand signals it as a tuple (Timed) success value.
If the current
Singleis empty or fails, the resultingSinglewill pass along the signals to the downstream. To measure the time to termination, usematerialize()and applytimeInterval(TimeUnit, Scheduler).- Scheduler:
timeIntervaluses the providedSchedulerfor determining the current time upon subscription and upon receiving the success item from the currentSingle.
- Parameters:
unit- the time unit for measurementscheduler- theSchedulerused for providing the current time- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<Timed<T>> timestamp()Combines the success value from the currentSinglewith the current time (in milliseconds) of its reception, using thecomputationScheduleras time source, then signals them as aTimedinstance.
If the current
Singleis empty or fails, the resultingSinglewill pass along the signals to the downstream. To get the timestamp of the error, usematerialize()and applytimestamp().- Scheduler:
timestampuses thecomputationSchedulerfor determining the current time upon receiving the success item from the currentSingle.
- Returns:
- the new
Singleinstance - Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<Timed<T>> timestamp(@NonNull @NonNull Scheduler scheduler) Combines the success value from the currentSinglewith the current time (in milliseconds) of its reception, using the givenScheduleras time source, then signals them as aTimedinstance.
If the current
Singleis empty or fails, the resultingSinglewill pass along the signals to the downstream. To get the timestamp of the error, usematerialize()and applytimestamp(Scheduler).- Scheduler:
timestampuses the providedSchedulerfor determining the current time upon receiving the success item from the currentSingle.
- Parameters:
scheduler- theSchedulerused for providing the current time- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifschedulerisnull- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<Timed<T>> timestamp(@NonNull @NonNull TimeUnit unit) Combines the success value from the currentSinglewith the current time of its reception, using thecomputationScheduleras time source, then signals it as aTimedinstance.
If the current
Singleis empty or fails, the resultingSinglewill pass along the signals to the downstream. To get the timestamp of the error, usematerialize()and applytimestamp(TimeUnit).- Scheduler:
timestampuses thecomputationScheduler, for determining the current time upon receiving the success item from the currentSingle.
- Parameters:
unit- the time unit for measurement- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<Timed<T>> timestamp(@NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Combines the success value from the currentSinglewith the current time of its reception, using the givenScheduleras time source, then signals it as aTimedinstance.
If the current
Singleis empty or fails, the resultingSinglewill pass along the signals to the downstream. To get the timestamp of the error, usematerialize()and applytimestamp(TimeUnit, Scheduler).- Scheduler:
timestampuses the providedScheduler, which is used for determining the current time upon receiving the success item from the currentSingle.
- Parameters:
unit- the time unit for measurementscheduler- theSchedulerused for providing the current time- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 3.0.0
-
takeUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> takeUntil(@NonNull @NonNull CompletableSource other) Returns aSinglethat emits the item emitted by the currentSingleuntil aCompletableSourceterminates. Upon termination ofother, this will emit aCancellationExceptionrather than go toSingleObserver.onSuccess(Object).
- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Parameters:
other- theCompletableSourcewhose termination will causetakeUntilto emit the item from the currentSingle- Returns:
- the new
Singlethat emits the item emitted by the currentSingleuntil such time asotherterminates. - Throws:
NullPointerException- ifotherisnull- See Also:
-
takeUntil
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull E> @NonNull Single<T> takeUntil(@NonNull @NonNull Flow.Publisher<@NonNull E> other) Returns aSinglethat emits the item emitted by the currentSingleuntil aFlow.Publisheremits an item or completes. Upon emission of an item fromother, this will emit aCancellationExceptionrather than go toSingleObserver.onSuccess(Object).
- Backpressure:
- The
otherpublisher is consumed in an unbounded fashion but will be cancelled after the first item it produced. - Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Type Parameters:
E- the type of items emitted byother- Parameters:
other- thePublisherwhose first emitted item or completion will causetakeUntilto emitCancellationExceptionif the currentSinglehasn't completed till then- Returns:
- the new
Singlethat emits the item emitted by the currentSingleuntil such time asotheremits its first item - Throws:
NullPointerException- ifotherisnull- See Also:
-
takeUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull E> @NonNull Single<T> takeUntil(@NonNull @NonNull SingleSource<? extends @NonNull E> other) Returns aSinglethat emits the item emitted by the currentSingleuntil a secondSingleemits an item. Upon emission of an item fromother, this will emit aCancellationExceptionrather than go toSingleObserver.onSuccess(Object).
- Scheduler:
takeUntildoes not operate by default on a particularScheduler.
- Type Parameters:
E- the type of item emitted byother- Parameters:
other- theSinglewhose emitted item will causetakeUntilto emitCancellationExceptionif the currentSinglehasn't completed till then- Returns:
- the new
Singlethat emits the item emitted by the currentSingleuntil such time asotheremits its item - Throws:
NullPointerException- ifotherisnull- See Also:
-
timeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit) Signals aTimeoutExceptionif the currentSingledoesn't signal a success value within the specified timeout window.
- Scheduler:
timeoutsignals theTimeoutExceptionon thecomputationScheduler.
- Parameters:
timeout- the timeout amountunit- the time unit- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitisnull- Since:
- 2.0
-
timeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler) Signals aTimeoutExceptionif the currentSingledoesn't signal a success value within the specified timeout window.
- Scheduler:
timeoutsignals theTimeoutExceptionon theScheduleryou specify.
- Parameters:
timeout- the timeout amountunit- the time unitscheduler- the targetSchedulerwhere the timeout is awaited and theTimeoutExceptionsignaled- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunitorschedulerisnull- Since:
- 2.0
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull SingleSource<? extends @NonNull T> fallback) Runs the currentSingleand if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSourcesubscribed to.
- Scheduler:
timeoutsubscribes to the otherSingleSourceon theScheduleryou specify.
- Parameters:
timeout- the timeout amountunit- the time unitscheduler- theSchedulerwhere the timeout is awaited and the subscription to other happensfallback- the otherSingleSourcethat gets subscribed to if the currentSingletimes out- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifunit,schedulerorfallbackisnull- Since:
- 2.0
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull TimeUnit unit, @NonNull @NonNull SingleSource<? extends @NonNull T> fallback) Runs the currentSingleand if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSourcesubscribed to.
- Scheduler:
timeoutsubscribes to the otherSingleSourceon thecomputationScheduler.
- Parameters:
timeout- the timeout amountunit- the time unitfallback- the otherSingleSourcethat gets subscribed to if the currentSingletimes out- Returns:
- the new
Singleinstance - Throws:
NullPointerException- iffallbackorunitisnull- Since:
- 2.0
-
to
@CheckReturnValue @SchedulerSupport("none") public final <R> R to(@NonNull @NonNull SingleConverter<@NonNull T, ? extends R> converter) Calls the specified converter function during assembly time and returns its resulting value.
This allows fluent conversion to any other type.
- Scheduler:
todoes not operate by default on a particularScheduler.
History: 2.1.7 - experimental
- Type Parameters:
R- the resulting object type- Parameters:
converter- the function that receives the currentSingleinstance and returns a value- Returns:
- the converted value
- Throws:
NullPointerException- ifconverterisnull- Since:
- 2.2
-
ignoreElement
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable ignoreElement()Returns aCompletablethat ignores the success value of thisSingleand signalsonCompleteinstead.
- Scheduler:
ignoreElementdoes not operate by default on a particularScheduler.
- Returns:
- the new
Completableinstance - Since:
- 2.1.13
-
toFlowable
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> toFlowable()Converts thisSingleinto aFlowable.
- Backpressure:
- The returned
Flowablehonors the backpressure of the downstream consumer. - Scheduler:
toFlowabledoes not operate by default on a particularScheduler.
- Returns:
- the new
Flowableinstance
-
toFuture
-
toMaybe
-
toObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> toObservable()Converts thisSingleinto anObservable.
- Scheduler:
toObservabledoes not operate by default on a particularScheduler.
- Returns:
- the new
Observableinstance
-
unsubscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> unsubscribeOn(@NonNull @NonNull Scheduler scheduler) Returns aSinglewhich makes sure when aSingleObserverdisposes theDisposable, that call is propagated up on the specifiedScheduler.
- Scheduler:
unsubscribeOncallsdispose()of the upstream on theScheduleryou specify.
History: 2.0.9 - experimental
- Parameters:
scheduler- the target scheduler where to execute the disposal- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifschedulerisnull- Since:
- 2.2
-
zipWith
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull U, @NonNull R> @NonNull Single<R> zipWith(@NonNull @NonNull SingleSource<@NonNull U> other, @NonNull @NonNull BiFunction<? super @NonNull 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.
- Scheduler:
zipWithdoes not operate by default on a particularScheduler.
- Type Parameters:
U- the type of items emitted by theotherSingleR- the type of items emitted by the resultingSingle- Parameters:
other- the otherSingleSourcezipper- a function that combines the pairs of items from the twoSingleSources to generate the items to be emitted by the resultingSingle- Returns:
- the new
Singlethat pairs up values from the currentSingleand theotherSingleSourceand emits the results ofzipFunctionapplied to these pairs - Throws:
NullPointerException- ifotherorzipperisnull- See Also:
-
test
Creates aTestObserverand subscribes it to thisSingle.
- Scheduler:
testdoes not operate by default on a particularScheduler.
- Returns:
- the new
TestObserverinstance - Since:
- 2.0
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<T> test(boolean dispose) Creates aTestObserveroptionally in cancelled state, then subscribes it to thisSingle.
- Scheduler:
testdoes not operate by default on a particularScheduler.
- Parameters:
dispose- iftrue, theTestObserverwill be cancelled before subscribing to thisSingle.- Returns:
- the new
TestObserverinstance - Since:
- 2.0
-
fromCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<@NonNull T> fromCompletionStage(@NonNull @NonNull CompletionStage<@NonNull T> stage) Signals the completion value or error of the given (hot)CompletionStage-based asynchronous calculation.
Note that the operator takes an already instantiated, running or terminated
CompletionStage. If theCompletionStageis to be created per consumer upon subscription, usedefer(Supplier)aroundfromCompletionStage:Single.defer(() -> Single.fromCompletionStage(createCompletionStage()));If the
CompletionStagecompletes withnull, the resultingSingleis terminated with aNullPointerException.Canceling the flow can't cancel the execution of the
CompletionStagebecauseCompletionStageitself doesn't support cancellation. Instead, the operator detaches from theCompletionStage.- Scheduler:
fromCompletionStagedoes not operate by default on a particularScheduler.
- Type Parameters:
T- the element type of theCompletionStage- Parameters:
stage- theCompletionStageto convert toSingleand signal its success value or error- Returns:
- the new
Singleinstance - Throws:
NullPointerException- ifstageisnull- Since:
- 3.0.0
-
mapOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Maybe<R> mapOptional(@NonNull @NonNull Function<? super @NonNull T, @NonNull Optional<? extends @NonNull R>> mapper) Maps the upstream success value into anOptionaland emits the contained item if not empty as aMaybe.
- Scheduler:
mapOptionaldoes not operate by default on a particularScheduler.
- Type Parameters:
R- the non-nulloutput type- Parameters:
mapper- the function that receives the upstream success item and should return a non-emptyOptionalto emit as the success output or an emptyOptionalto complete theMaybe- Returns:
- the new
Maybeinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
toCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull CompletionStage<T> toCompletionStage()Signals the upstream success item (or error) via aCompletionStage.
The upstream can be canceled by converting the resulting
CompletionStageintoCompletableFutureviaCompletionStage.toCompletableFuture()and callingCompletableFuture.cancel(boolean)on it. The upstream will be also cancelled if the resultingCompletionStageis converted to and completed manually byCompletableFuture.complete(Object)orCompletableFuture.completeExceptionally(Throwable).- Scheduler:
toCompletionStagedoes not operate by default on a particularScheduler.
- Returns:
- the new
CompletionStageinstance - Since:
- 3.0.0
-
flattenStreamAsFlowable
@CheckReturnValue @SchedulerSupport("none") @BackpressureSupport(FULL) @NonNull public final <@NonNull R> @NonNull Flowable<R> flattenStreamAsFlowable(@NonNull @NonNull Function<? super @NonNull T, @NonNull ? extends Stream<? extends @NonNull R>> mapper) Maps the upstream succecss value into a JavaStreamand emits its items to the downstream consumer as aFlowable.
The operator closes the
Streamupon cancellation and when it terminates. The exceptions raised when closing aStreamare routed to the global error handler (RxJavaPlugins.onError(Throwable). If aStreamshould not be closed, turn it into anIterableand useflattenAsFlowable(Function):source.flattenAsFlowable(item -> createStream(item)::iterator);Primitive streams are not supported and items have to be boxed manually (e.g., via
IntStream.boxed()):source.flattenStreamAsFlowable(item -> IntStream.rangeClosed(1, 10).boxed());Streamdoes not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Backpressure:
- The operator honors backpressure from downstream and iterates the given
Streamon demand (i.e., when requested). - Scheduler:
flattenStreamAsFlowabledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of theStreamand the outputFlowable- Parameters:
mapper- the function that receives the upstream success item and should return aStreamof values to emit.- Returns:
- the new
Flowableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-
flattenStreamAsObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flattenStreamAsObservable(@NonNull @NonNull Function<? super @NonNull 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.
The operator closes the
Streamupon cancellation and when it terminates. The exceptions raised when closing aStreamare routed to the global error handler (RxJavaPlugins.onError(Throwable). If aStreamshould not be closed, turn it into anIterableand useflattenAsObservable(Function):source.flattenAsObservable(item -> createStream(item)::iterator);Primitive streams are not supported and items have to be boxed manually (e.g., via
IntStream.boxed()):source.flattenStreamAsObservable(item -> IntStream.rangeClosed(1, 10).boxed());Streamdoes not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Scheduler:
flattenStreamAsObservabledoes not operate by default on a particularScheduler.
- Type Parameters:
R- the element type of theStreamand the outputObservable- Parameters:
mapper- the function that receives the upstream success item and should return aStreamof values to emit.- Returns:
- the new
Observableinstance - Throws:
NullPointerException- ifmapperisnull- Since:
- 3.0.0
- See Also:
-