Class Single<T>
- java.lang.Object
-
- io.reactivex.rxjava3.core.Single<T>
-
- Type Parameters:
T
- the type of the item emitted by theSingle
- All Implemented Interfaces:
SingleSource<T>
- Direct Known Subclasses:
CompletableMaterialize
,CompletableToSingle
,FlowableAllSingle
,FlowableAnySingle
,FlowableCollectSingle
,FlowableCollectWithCollectorSingle
,FlowableCountSingle
,FlowableElementAtSingle
,FlowableLastSingle
,FlowableReduceSeedSingle
,FlowableReduceWithSingle
,FlowableSequenceEqualSingle
,FlowableSingleSingle
,FlowableToListSingle
,MaybeContains
,MaybeCount
,MaybeEqualSingle
,MaybeIsEmptySingle
,MaybeMaterialize
,MaybeSwitchIfEmptySingle
,MaybeToSingle
,ObservableAllSingle
,ObservableAnySingle
,ObservableCollectSingle
,ObservableCollectWithCollectorSingle
,ObservableCountSingle
,ObservableElementAtSingle
,ObservableLastSingle
,ObservableReduceSeedSingle
,ObservableReduceWithSingle
,ObservableSequenceEqualSingle
,ObservableSingleSingle
,ObservableToListSingle
,SingleAmb
,SingleCache
,SingleContains
,SingleCreate
,SingleDefer
,SingleDelay
,SingleDelayWithCompletable
,SingleDelayWithObservable
,SingleDelayWithPublisher
,SingleDelayWithSingle
,SingleDetach
,SingleDoAfterSuccess
,SingleDoAfterTerminate
,SingleDoFinally
,SingleDoOnDispose
,SingleDoOnError
,SingleDoOnEvent
,SingleDoOnLifecycle
,SingleDoOnSubscribe
,SingleDoOnSuccess
,SingleDoOnTerminate
,SingleEquals
,SingleError
,SingleFlatMap
,SingleFlatMapBiSelector
,SingleFlatMapNotification
,SingleFromCallable
,SingleFromCompletionStage
,SingleFromPublisher
,SingleFromSupplier
,SingleFromUnsafeSource
,SingleHide
,SingleJust
,SingleLift
,SingleMap
,SingleMaterialize
,SingleNever
,SingleObserveOn
,SingleOnErrorReturn
,SingleResumeNext
,SingleSubject
,SingleSubscribeOn
,SingleTakeUntil
,SingleTimeInterval
,SingleTimeout
,SingleTimer
,SingleUnsubscribeOn
,SingleUsing
,SingleZipArray
,SingleZipIterable
public abstract class Single<@NonNull T> extends java.lang.Object implements SingleSource<T>
TheSingle
class implements the Reactive Pattern for a single value response.Single
behaves similarly toObservable
except that it can only emit either a single successful value or an error (there is noonComplete
notification as there is for anObservable
).The
Single
class implements theSingleSource
base interface and the default consumer type it interacts with is theSingleObserver
via thesubscribe(SingleObserver)
method.The
Single
operates with the following sequential protocol:onSubscribe (onSuccess | onError)?
Note that
onSuccess
andonError
are mutually exclusive events; unlikeObservable
,onSuccess
is never followed byonError
.Like
Observable
, a runningSingle
can be stopped through theDisposable
instance provided to consumers throughSingleObserver.onSubscribe(io.reactivex.rxjava3.disposables.Disposable)
.Like an
Observable
, aSingle
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
orObservable
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 thevoid
return of thesubscribe(SingleObserver)
method) and it is the responsibility of the implementor of theSingleObserver
to allow this to happen. RxJava supports such usage with the standardDisposableSingleObserver
instance. For convenience, thesubscribeWith(SingleObserver)
method is provided as well to allow working with aSingleObserver
(or subclass) instance to be applied with in a fluent manner (such as in the example above).- Since:
- 2.0
- See Also:
DisposableSingleObserver
-
-
Constructor Summary
Constructors Constructor Description Single()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <@NonNull T>
@NonNull Single<T>amb(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Runs multipleSingleSource
s and signals the events of the first one that signals (disposing the rest).static <@NonNull T>
@NonNull Single<T>ambArray(@NonNull SingleSource<? extends @NonNull T>... sources)
Runs multipleSingleSource
s and signals the events of the first one that signals (disposing the rest).@NonNull Single<T>
ambWith(@NonNull SingleSource<? extends @NonNull T> other)
Signals the event of this or the otherSingleSource
whichever signals first.T
blockingGet()
Waits in a blocking fashion until the currentSingle
signals a success value (which is returned) or an exception (which is propagated).void
blockingSubscribe()
Subscribes to the currentSingle
and blocks the current thread until it terminates.void
blockingSubscribe(@NonNull SingleObserver<? super @NonNull T> observer)
Subscribes to the currentSingle
and calls the appropriateSingleObserver
method on the current thread.void
blockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to the currentSingle
and calls givenonSuccess
callback on the current thread when it completes normally.void
blockingSubscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to the currentSingle
and calls the appropriate callback on the current thread when it terminates.@NonNull Single<T>
cache()
Stores the success value or exception from the currentSingle
and replays it to lateSingleObserver
s.<@NonNull U>
@NonNull Single<U>cast(@NonNull java.lang.Class<? extends @NonNull U> clazz)
Casts the success value of the currentSingle
into the target type or signals aClassCastException
if not compatible.<@NonNull R>
@NonNull Single<R>compose(@NonNull SingleTransformer<? super @NonNull T,? extends @NonNull R> transformer)
Transform aSingle
by applying a particularSingleTransformer
function 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 theSingleSource
s provided by anObservableSource
sequence.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2)
Returns aFlowable
that emits the items emitted by twoSingleSource
s, one after the other.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3)
Returns aFlowable
that emits the items emitted by threeSingleSource
s, one after the other.static <@NonNull T>
@NonNull Flowable<T>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 aFlowable
that emits the items emitted by fourSingleSource
s, one after the other.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided by anIterable
sequence.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided by aPublisher
sequence.static <@NonNull T>
@NonNull Flowable<T>concat(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int prefetch)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided by aPublisher
sequence and prefetched by the specified amount.static <@NonNull T>
@NonNull Flowable<T>concatArray(@NonNull SingleSource<? extends @NonNull T>... sources)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided in an array.static <@NonNull T>
@NonNull Flowable<T>concatArrayDelayError(@NonNull SingleSource<? extends @NonNull T>... sources)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided in an array.static <@NonNull T>
@NonNull Flowable<T>concatArrayEager(@NonNull SingleSource<? extends @NonNull T>... sources)
Concatenates a sequence ofSingleSource
eagerly into a single stream of values.static <@NonNull T>
@NonNull Flowable<T>concatArrayEagerDelayError(@NonNull SingleSource<? extends @NonNull T>... sources)
Concatenates a sequence ofSingleSource
eagerly into a single stream of values.static <@NonNull T>
@NonNull Flowable<T>concatDelayError(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates theIterable
sequence ofSingleSource
s into a single sequence by subscribing to eachSingleSource
, one after the other, one at a time and delays any errors till the all innerSingleSource
s terminate as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatDelayError(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates thePublisher
sequence ofSingleSource
s 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 outerPublisher
terminate as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatDelayError(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int prefetch)
Concatenates thePublisher
sequence ofSingleSource
s 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 outerPublisher
terminate as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates anIterable
sequence ofSingleSource
s eagerly into a single stream of values.static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates anIterable
sequence ofSingleSource
s eagerly into a single stream of values and runs a limited number of the inner sources at once.static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates aPublisher
sequence ofSingleSource
s eagerly into a single stream of values.static <@NonNull T>
@NonNull Flowable<T>concatEager(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofSingleSource
s eagerly into a single stream of values and runs a limited number of those innerSingleSource
s at once.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates anIterable
sequence ofSingleSource
s eagerly into a single stream of values, delaying errors until all the inner sources terminate.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates anIterable
sequence ofSingleSource
s eagerly into a single stream of values, delaying errors until all the inner sources terminate.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates aPublisher
sequence ofSingleSource
s eagerly into a single stream of values, delaying errors until all the inner and the outer sequence terminate.static <@NonNull T>
@NonNull Flowable<T>concatEagerDelayError(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofSingleSource
s eagerly into a single stream of values, running at most the specified number of those innerSingleSource
s at once and delaying errors until all the inner and the outer sequence terminate.<@NonNull R>
@NonNull Single<R>concatMap(@NonNull Function<? super @NonNull T,? extends SingleSource<? extends @NonNull R>> mapper)
Returns aSingle
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns aSingleSource
.@NonNull Completable
concatMapCompletable(@NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that completes based on applying a specified function to the item emitted by the currentSingle
, where that function returns aCompletableSource
.<@NonNull R>
@NonNull Maybe<R>concatMapMaybe(@NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> mapper)
Returns aMaybe
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns aMaybeSource
.@NonNull Flowable<T>
concatWith(@NonNull SingleSource<? extends @NonNull T> other)
Returns aFlowable
that emits the item emitted by the currentSingle
, then the item emitted by the specifiedSingleSource
.@NonNull Single<java.lang.Boolean>
contains(@NonNull java.lang.Object item)
Signalstrue
if the currentSingle
signals a success value that isObject.equals(Object)
with the value provided.@NonNull Single<java.lang.Boolean>
contains(@NonNull java.lang.Object item, @NonNull BiPredicate<java.lang.Object,java.lang.Object> comparer)
Signalstrue
if the currentSingle
signals a success value that is equal with the value provided by calling aBiPredicate
.static <@NonNull T>
@NonNull Single<T>create(@NonNull SingleOnSubscribe<@NonNull T> source)
Provides an API (via a coldSingle
) that bridges the reactive world with the callback-style world.static <@NonNull T>
@NonNull Single<T>defer(@NonNull Supplier<? extends @NonNull SingleSource<? extends @NonNull T>> supplier)
Calls aSupplier
for each individualSingleObserver
to return the actualSingleSource
to be subscribed to.@NonNull Single<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit)
Delays the emission of the success signal from the currentSingle
by the specified amount.@NonNull Single<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, boolean delayError)
Delays the emission of the success or error signal from the currentSingle
by the specified amount.@NonNull Single<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Delays the emission of the success signal from the currentSingle
by the specified amount.@NonNull Single<T>
delay(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler, boolean delayError)
Delays the emission of the success or error signal from the currentSingle
by the specified amount.@NonNull Single<T>
delaySubscription(long time, @NonNull java.util.concurrent.TimeUnit unit)
Delays the actual subscription to the currentSingle
until the given time delay elapsed.@NonNull Single<T>
delaySubscription(long time, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Delays the actual subscription to the currentSingle
until the given time delay elapsed.@NonNull Single<T>
delaySubscription(@NonNull CompletableSource subscriptionIndicator)
Delays the actual subscription to the currentSingle
until the given otherCompletableSource
completes.<@NonNull U>
@NonNull Single<T>delaySubscription(@NonNull ObservableSource<@NonNull U> subscriptionIndicator)
Delays the actual subscription to the currentSingle
until the given otherObservableSource
signals its first value or completes.<@NonNull U>
@NonNull Single<T>delaySubscription(@NonNull SingleSource<@NonNull U> subscriptionIndicator)
Delays the actual subscription to the currentSingle
until the given otherSingleSource
signals success.<@NonNull U>
@NonNull Single<T>delaySubscription(@NonNull org.reactivestreams.Publisher<@NonNull U> subscriptionIndicator)
Delays the actual subscription to the currentSingle
until the given otherPublisher
signals its first value or completes.<@NonNull R>
@NonNull Maybe<R>dematerialize(@NonNull Function<? super @NonNull T,@NonNull Notification<@NonNull R>> selector)
Maps theNotification
success value of the currentSingle
back into normalonSuccess
,onError
oronComplete
signals as aMaybe
source.@NonNull Single<T>
doAfterSuccess(@NonNull Consumer<? super @NonNull T> onAfterSuccess)
Calls the specified consumer with the success item after this item has been emitted to the downstream.@NonNull Single<T>
doAfterTerminate(@NonNull Action onAfterTerminate)
@NonNull Single<T>
doFinally(@NonNull Action onFinally)
Calls the specified action after thisSingle
signalsonSuccess
oronError
or gets disposed by the downstream.@NonNull Single<T>
doOnDispose(@NonNull Action onDispose)
Calls the sharedAction
if aSingleObserver
subscribed to the currentSingle
disposes the commonDisposable
it received viaonSubscribe
.@NonNull Single<T>
doOnError(@NonNull Consumer<? super java.lang.Throwable> onError)
Calls the shared consumer with the error sent viaonError
for eachSingleObserver
that subscribes to the currentSingle
.@NonNull Single<T>
doOnEvent(@NonNull BiConsumer<? super @NonNull T,? super java.lang.Throwable> onEvent)
Calls the shared consumer with the error sent viaonError
or the value viaonSuccess
for eachSingleObserver
that subscribes to the currentSingle
.@NonNull Single<T>
doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe, @NonNull Action onDispose)
Calls the appropriateonXXX
method (shared between allSingleObserver
s) for the lifecycle events of the sequence (subscription, disposal).@NonNull Single<T>
doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe)
Calls the shared consumer with theDisposable
sent through theonSubscribe
for eachSingleObserver
that subscribes to the currentSingle
.@NonNull Single<T>
doOnSuccess(@NonNull Consumer<? super @NonNull T> onSuccess)
Calls the shared consumer with the success value sent viaonSuccess
for eachSingleObserver
that subscribes to the currentSingle
.@NonNull Single<T>
doOnTerminate(@NonNull Action onTerminate)
Returns aSingle
instance that calls the givenonTerminate
callback just before thisSingle
completes normally or with an exception.static <@NonNull T>
@NonNull Single<T>error(@NonNull Supplier<? extends @NonNull java.lang.Throwable> supplier)
Signals aThrowable
returned by the callback function for each individualSingleObserver
.static <@NonNull T>
@NonNull Single<T>error(@NonNull java.lang.Throwable throwable)
Returns aSingle
that invokes a subscriber'sonError
method when the subscriber subscribes to it.@NonNull Maybe<T>
filter(@NonNull Predicate<? super @NonNull T> predicate)
Filters the success item of theSingle
via a predicate function and emitting it if the predicate returnstrue
, completing otherwise.<@NonNull R>
@NonNull Single<R>flatMap(@NonNull Function<? super @NonNull T,? extends SingleSource<? extends @NonNull R>> mapper)
Returns aSingle
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns aSingleSource
.<@NonNull R>
@NonNull Single<R>flatMap(@NonNull Function<? super @NonNull T,? extends SingleSource<? extends @NonNull R>> onSuccessMapper, @NonNull Function<? super java.lang.Throwable,? extends SingleSource<? extends @NonNull R>> onErrorMapper)
Maps theonSuccess
oronError
signals of the currentSingle
into aSingleSource
and emits thatSingleSource
's signals.<@NonNull U,@NonNull R>
@NonNull Single<R>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 aSingle
that emits the results of a specified function to the pair of values emitted by the currentSingle
and a specified mappedSingleSource
.@NonNull Completable
flatMapCompletable(@NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that completes based on applying a specified function to the item emitted by the currentSingle
, where that function returns aCompletableSource
.<@NonNull R>
@NonNull Maybe<R>flatMapMaybe(@NonNull Function<? super @NonNull T,? extends MaybeSource<? extends @NonNull R>> mapper)
Returns aMaybe
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns aMaybeSource
.<@NonNull R>
@NonNull Observable<R>flatMapObservable(@NonNull Function<? super @NonNull T,? extends ObservableSource<? extends @NonNull R>> mapper)
Returns anObservable
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns anObservableSource
.<@NonNull R>
@NonNull Flowable<R>flatMapPublisher(@NonNull Function<? super @NonNull T,? extends org.reactivestreams.Publisher<? extends @NonNull R>> mapper)
Returns aFlowable
that emits items based on applying a specified function to the item emitted by the currentSingle
, where that function returns aPublisher
.<@NonNull U>
@NonNull Flowable<U>flattenAsFlowable(@NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentSingle
into anIterable
and emits its items as aFlowable
sequence.<@NonNull U>
@NonNull Observable<U>flattenAsObservable(@NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentSingle
into anIterable
and emits its items as anObservable
sequence.<@NonNull R>
@NonNull Flowable<R>flattenStreamAsFlowable(@NonNull Function<? super @NonNull T,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as aFlowable
.<@NonNull R>
@NonNull Observable<R>flattenStreamAsObservable(@NonNull Function<? super @NonNull T,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as anObservable
.static <@NonNull T>
@NonNull Single<T>fromCallable(@NonNull java.util.concurrent.Callable<? extends @NonNull T> callable)
Returns aSingle
that invokes the givenCallable
for each incomingSingleObserver
and emits its value or exception to them.static <@NonNull T>
@NonNull Single<@NonNull T>fromCompletionStage(@NonNull java.util.concurrent.CompletionStage<@NonNull T> stage)
Signals the completion value or error of the given (hot)CompletionStage
-based asynchronous calculation.static <@NonNull T>
@NonNull Single<T>fromFuture(@NonNull java.util.concurrent.Future<? extends @NonNull T> future)
Converts aFuture
into aSingle
and awaits its outcome in a blocking fashion.static <@NonNull T>
@NonNull Single<T>fromFuture(@NonNull java.util.concurrent.Future<? extends @NonNull T> future, long timeout, @NonNull java.util.concurrent.TimeUnit unit)
Converts aFuture
into aSingle
and awaits its outcome, or timeout, in a blocking fashion.static <@NonNull T>
@NonNull Single<T>fromMaybe(@NonNull MaybeSource<@NonNull T> maybe)
Returns aSingle
instance that when subscribed to, subscribes to theMaybeSource
instance and emitsonSuccess
as a single item, turns anonComplete
intoNoSuchElementException
error signal or forwards theonError
signal.static <@NonNull T>
@NonNull Single<T>fromMaybe(@NonNull MaybeSource<@NonNull T> maybe, @NonNull T defaultItem)
Returns aSingle
instance that when subscribed to, subscribes to theMaybeSource
instance and emitsonSuccess
as a single item, emits thedefaultItem
for anonComplete
signal or forwards theonError
signal.static <@NonNull T>
@NonNull Single<T>fromObservable(@NonNull ObservableSource<? extends @NonNull T> observable)
Wraps a specificObservableSource
into aSingle
and signals its single element or error.static <@NonNull T>
@NonNull Single<T>fromPublisher(@NonNull org.reactivestreams.Publisher<? extends @NonNull T> publisher)
Wraps a specificPublisher
into aSingle
and signals its single element or error.static <@NonNull T>
@NonNull Single<T>fromSupplier(@NonNull Supplier<? extends @NonNull T> supplier)
Returns aSingle
that invokes passed supplier and emits its result for each individualSingleObserver
that subscribes.@NonNull Single<T>
hide()
Hides the identity of the currentSingle
, including theDisposable
that is sent to the downstream viaonSubscribe()
.@NonNull Completable
ignoreElement()
static <@NonNull T>
@NonNull Single<T>just(@NonNull T item)
Returns aSingle
that emits a specified item.<@NonNull R>
@NonNull Single<R>lift(@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 aSingle
which, when subscribed to, invokes theapply(SingleObserver)
method of the providedSingleOperator
for each individual downstreamSingle
and allows the insertion of a custom operator by accessing the downstream'sSingleObserver
during 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.<@NonNull R>
@NonNull Single<R>map(@NonNull Function<? super @NonNull T,? extends @NonNull R> mapper)
Returns aSingle
that applies a specified function to the item emitted by the currentSingle
and emits the result of this function application.<@NonNull R>
@NonNull Maybe<R>mapOptional(@NonNull Function<? super @NonNull T,@NonNull java.util.Optional<? extends @NonNull R>> mapper)
Maps the upstream success value into anOptional
and emits the contained item if not empty as aMaybe
.@NonNull Single<Notification<T>>
materialize()
Maps the signal types of thisSingle
into aNotification
of the same kind and emits it as a single success value to downstream.static <@NonNull T>
@NonNull Single<T>merge(@NonNull SingleSource<? extends SingleSource<? extends @NonNull T>> source)
Flattens aSingleSource
that emits aSingleSingle
into a singleSingle
that emits the item emitted by the nestedSingleSource
, without any transformation.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2)
Flattens twoSingleSource
s into oneFlowable
sequence, without any transformation.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3)
Flattens threeSingleSource
s into oneFlowable
sequence, without any transformation.static <@NonNull T>
@NonNull Flowable<T>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 fourSingleSource
s into oneFlowable
sequence, without any transformation.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Merges anIterable
sequence ofSingleSource
instances into a singleFlowable
sequence, running allSingleSource
s at once.static <@NonNull T>
@NonNull Flowable<T>merge(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Merges a sequence ofSingleSource
instances emitted by aPublisher
into a singleFlowable
sequence, running allSingleSource
s at once.static <@NonNull T>
@NonNull Flowable<T>mergeArray(SingleSource<? extends @NonNull T>... sources)
Merges an array ofSingleSource
instances into a singleFlowable
sequence, running allSingleSource
s at once.static <@NonNull T>
@NonNull Flowable<T>mergeArrayDelayError(@NonNull SingleSource<? extends @NonNull T>... sources)
Flattens an array ofSingleSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceSingleSource
s without being interrupted by an error notification from one of them.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2)
Flattens twoSingleSource
s into oneFlowable
, without any transformation, delaying any error(s) until all sources succeed or fail.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2, @NonNull SingleSource<? extends @NonNull T> source3)
Flattens twoSingleSource
s into oneFlowable
, without any transformation, delaying any error(s) until all sources succeed or fail.static <@NonNull T>
@NonNull Flowable<T>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 twoSingleSource
s into oneFlowable
, without any transformation, delaying any error(s) until all sources succeed or fail.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Merges anIterable
sequence ofSingleSource
instances into oneFlowable
sequence, running allSingleSource
s at once and delaying any error(s) until all sources succeed or fail.static <@NonNull T>
@NonNull Flowable<T>mergeDelayError(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Merges a sequence ofSingleSource
instances emitted by aPublisher
into aFlowable
sequence, running allSingleSource
s at once and delaying any error(s) until all sources succeed or fail.@NonNull Flowable<T>
mergeWith(@NonNull SingleSource<? extends @NonNull T> other)
static <@NonNull T>
@NonNull Single<T>never()
Returns a singleton instance of a never-signalingSingle
(only callsonSubscribe
).@NonNull Single<T>
observeOn(@NonNull Scheduler scheduler)
Signals the success item or the terminal signals of the currentSingle
on the specifiedScheduler
, asynchronously.<@NonNull U>
@NonNull Maybe<U>ofType(@NonNull java.lang.Class<@NonNull U> clazz)
Filters the items emitted by the currentSingle
, only emitting its success value if that is an instance of the suppliedClass
.@NonNull Maybe<T>
onErrorComplete()
Returns aMaybe
instance that if the currentSingle
emits an error, it will emit anonComplete
and swallow the throwable.@NonNull Maybe<T>
onErrorComplete(@NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aMaybe
instance that if thisSingle
emits an error and the predicate returnstrue
, it will emit anonComplete
and swallow the throwable.@NonNull Single<T>
onErrorResumeNext(@NonNull Function<? super java.lang.Throwable,? extends SingleSource<? extends @NonNull T>> fallbackSupplier)
Resumes the flow with aSingleSource
returned for the failureThrowable
of the currentSingle
by a function instead of signaling the error viaonError
.@NonNull Single<T>
onErrorResumeWith(@NonNull SingleSource<? extends @NonNull T> fallback)
Resumes the flow with the givenSingleSource
when the currentSingle
fails instead of signaling the error viaonError
.@NonNull Single<T>
onErrorReturn(@NonNull Function<java.lang.Throwable,? extends @NonNull T> itemSupplier)
Ends the flow with a success item returned by a function for theThrowable
error signaled by the currentSingle
instead of signaling the error viaonError
.@NonNull Single<T>
onErrorReturnItem(@NonNull T item)
Signals the specified value as success in case the currentSingle
signals an error.@NonNull Single<T>
onTerminateDetach()
Nulls out references to the upstream producer and downstreamSingleObserver
if the sequence is terminated or downstream callsdispose()
.@NonNull Flowable<T>
repeat()
Repeatedly re-subscribes to the currentSingle
and emits each success value as aFlowable
sequence.@NonNull Flowable<T>
repeat(long times)
Re-subscribes to the currentSingle
at most the given number of times and emits each success value as aFlowable
sequence.@NonNull Flowable<T>
repeatUntil(@NonNull BooleanSupplier stop)
Re-subscribes to the currentSingle
until the givenBooleanSupplier
returnstrue
and emits the success items as aFlowable
sequence.@NonNull Flowable<T>
repeatWhen(@NonNull Function<? super Flowable<java.lang.Object>,? extends org.reactivestreams.Publisher<?>> handler)
Re-subscribes to the currentSingle
if thePublisher
returned by the handler function signals a value in response to a value signaled through theFlowable
the handler receives.@NonNull Single<T>
retry()
Repeatedly re-subscribes to the currentSingle
indefinitely if it fails with anonError
.@NonNull Single<T>
retry(long times)
Repeatedly re-subscribe at most the specified times to the currentSingle
if it fails with anonError
.@NonNull Single<T>
retry(long times, @NonNull Predicate<? super java.lang.Throwable> predicate)
Repeatedly re-subscribe at most times or until the predicate returnsfalse
, whichever happens first if it fails with anonError
.@NonNull Single<T>
retry(@NonNull BiPredicate<? super java.lang.Integer,? super java.lang.Throwable> predicate)
Re-subscribe to the currentSingle
if the given predicate returnstrue
when theSingle
fails with anonError
.@NonNull Single<T>
retry(@NonNull Predicate<? super java.lang.Throwable> predicate)
Re-subscribe to the currentSingle
if the given predicate returnstrue
when theSingle
fails with anonError
.@NonNull Single<T>
retryUntil(@NonNull BooleanSupplier stop)
Retries until the given stop function returnstrue
.@NonNull Single<T>
retryWhen(@NonNull Function<? super Flowable<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> handler)
Re-subscribes to the currentSingle
if and when thePublisher
returned by the handler function signals a value.void
safeSubscribe(@NonNull SingleObserver<? super @NonNull T> observer)
Wraps the givenSingleObserver
, catches anyRuntimeException
s thrown by itsSingleObserver.onSubscribe(Disposable)
,SingleObserver.onSuccess(Object)
orSingleObserver.onError(Throwable)
methods* and routes those to the global error handler viaRxJavaPlugins.onError(Throwable)
.static <@NonNull T>
@NonNull Single<java.lang.Boolean>sequenceEqual(@NonNull SingleSource<? extends @NonNull T> source1, @NonNull SingleSource<? extends @NonNull T> source2)
Compares twoSingleSource
s and emitstrue
if they emit the same value (compared viaObject.equals(Object)
).@NonNull Flowable<T>
startWith(@NonNull CompletableSource other)
Returns aFlowable
which first runs the otherCompletableSource
then the currentSingle
if the other completed normally.@NonNull Flowable<T>
startWith(@NonNull MaybeSource<@NonNull T> other)
Returns aFlowable
which first runs the otherMaybeSource
then the currentSingle
if the other succeeded or completed normally.@NonNull Observable<T>
startWith(@NonNull ObservableSource<@NonNull T> other)
Returns anObservable
which first delivers the events of the otherObservableSource
then runs the currentSingle
.@NonNull Flowable<T>
startWith(@NonNull SingleSource<@NonNull T> other)
Returns aFlowable
which first runs the otherSingleSource
then the currentSingle
if the other succeeded normally.@NonNull Flowable<T>
startWith(@NonNull org.reactivestreams.Publisher<@NonNull T> other)
Returns aFlowable
which first delivers the events of the otherPublisher
then runs the currentSingle
.@NonNull Disposable
subscribe()
Subscribes to aSingle
but ignore its emission or notification.void
subscribe(@NonNull SingleObserver<? super @NonNull T> observer)
Subscribes the givenSingleObserver
to thisSingleSource
instance.@NonNull Disposable
subscribe(@NonNull BiConsumer<? super @NonNull T,? super java.lang.Throwable> onCallback)
Subscribes to aSingle
and provides a composite callback to handle the item it emits or any error notification it issues.@NonNull Disposable
subscribe(@NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to aSingle
and provides a callback to handle the item it emits.@NonNull Disposable
subscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to aSingle
and provides callbacks to handle the item it emits or any error notification it issues.@NonNull Disposable
subscribe(@NonNull Consumer<? super @NonNull T> onSuccess, @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull DisposableContainer container)
Wraps the given onXXX callbacks into aDisposable
SingleObserver
, adds it to the givenDisposableContainer
and ensures, that if the upstream terminates or this particularDisposable
is disposed, theSingleObserver
is removed from the given container.protected abstract void
subscribeActual(@NonNull SingleObserver<? super @NonNull T> observer)
Implement this method in subclasses to handle the incomingSingleObserver
s.@NonNull Single<T>
subscribeOn(@NonNull Scheduler scheduler)
<@NonNull E extends SingleObserver<? super @NonNull T>>
EsubscribeWith(@NonNull E observer)
Subscribes a givenSingleObserver
(subclass) to thisSingle
and returns the givenSingleObserver
as is.static <@NonNull T>
@NonNull Flowable<T>switchOnNext(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Switches betweenSingleSource
s emitted by the sourcePublisher
whenever a newSingleSource
is emitted, disposing the previously runningSingleSource
, exposing the success items as aFlowable
sequence.static <@NonNull T>
@NonNull Flowable<T>switchOnNextDelayError(@NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Switches betweenSingleSource
s emitted by the sourcePublisher
whenever a newSingleSource
is emitted, disposing the previously runningSingleSource
, exposing the success items as aFlowable
sequence and delaying all errors from all of them until all terminate.@NonNull Single<T>
takeUntil(@NonNull CompletableSource other)
Returns aSingle
that emits the item emitted by the currentSingle
until aCompletableSource
terminates.<@NonNull E>
@NonNull Single<T>takeUntil(@NonNull SingleSource<? extends @NonNull E> other)
Returns aSingle
that emits the item emitted by the currentSingle
until a secondSingle
emits an item.<@NonNull E>
@NonNull Single<T>takeUntil(@NonNull org.reactivestreams.Publisher<@NonNull E> other)
Returns aSingle
that emits the item emitted by the currentSingle
until aPublisher
emits an item or completes.@NonNull TestObserver<T>
test()
Creates aTestObserver
and subscribes it to thisSingle
.@NonNull TestObserver<T>
test(boolean dispose)
Creates aTestObserver
optionally in cancelled state, then subscribes it to thisSingle
.@NonNull Single<Timed<T>>
timeInterval()
Measures the time (in milliseconds) between the subscription and success item emission of the currentSingle
and signals it as a tuple (Timed
) success value.@NonNull Single<Timed<T>>
timeInterval(@NonNull Scheduler scheduler)
Measures the time (in milliseconds) between the subscription and success item emission of the currentSingle
and signals it as a tuple (Timed
) success value.@NonNull Single<Timed<T>>
timeInterval(@NonNull java.util.concurrent.TimeUnit unit)
Measures the time between the subscription and success item emission of the currentSingle
and signals it as a tuple (Timed
) success value.@NonNull Single<Timed<T>>
timeInterval(@NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Measures the time between the subscription and success item emission of the currentSingle
and signals it as a tuple (Timed
) success value.@NonNull Single<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit)
Signals aTimeoutException
if the currentSingle
doesn't signal a success value within the specified timeout window.@NonNull Single<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Signals aTimeoutException
if the currentSingle
doesn't signal a success value within the specified timeout window.@NonNull Single<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler, @NonNull SingleSource<? extends @NonNull T> fallback)
Runs the currentSingle
and if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSource
subscribed to.@NonNull Single<T>
timeout(long timeout, @NonNull java.util.concurrent.TimeUnit unit, @NonNull SingleSource<? extends @NonNull T> fallback)
Runs the currentSingle
and if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSource
subscribed to.private Single<T>
timeout0(long timeout, java.util.concurrent.TimeUnit unit, Scheduler scheduler, SingleSource<? extends @NonNull T> fallback)
static @NonNull Single<java.lang.Long>
timer(long delay, @NonNull java.util.concurrent.TimeUnit unit)
Signals success with 0L value after the given delay when aSingleObserver
subscribes.static @NonNull Single<java.lang.Long>
timer(long delay, @NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
Signals success with 0L value on the specifiedScheduler
after the given delay when aSingleObserver
subscribes.@NonNull Single<Timed<T>>
timestamp()
@NonNull Single<Timed<T>>
timestamp(@NonNull Scheduler scheduler)
@NonNull Single<Timed<T>>
timestamp(@NonNull java.util.concurrent.TimeUnit unit)
@NonNull Single<Timed<T>>
timestamp(@NonNull java.util.concurrent.TimeUnit unit, @NonNull Scheduler scheduler)
<R> R
to(@NonNull SingleConverter<@NonNull T,? extends R> converter)
Calls the specified converter function during assembly time and returns its resulting value.@NonNull java.util.concurrent.CompletionStage<T>
toCompletionStage()
Signals the upstream success item (or error) via aCompletionStage
.@NonNull Flowable<T>
toFlowable()
Converts thisSingle
into aFlowable
.@NonNull java.util.concurrent.Future<T>
toFuture()
Returns aFuture
representing the single value emitted by thisSingle
.@NonNull Maybe<T>
toMaybe()
Converts thisSingle
into aMaybe
.@NonNull Observable<T>
toObservable()
Converts thisSingle
into anObservable
.private static <T> @NonNull Single<T>
toSingle(@NonNull Flowable<T> source)
static <@NonNull T>
@NonNull Single<T>unsafeCreate(@NonNull SingleSource<@NonNull T> onSubscribe)
Advanced use only: creates aSingle
instance without any safeguards by using a callback that is called with aSingleObserver
.@NonNull Single<T>
unsubscribeOn(@NonNull Scheduler scheduler)
Returns aSingle
which makes sure when aSingleObserver
disposes theDisposable
, that call is propagated up on the specifiedScheduler
.static <@NonNull T,@NonNull U>
@NonNull Single<T>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 aSingleSource
instance generated from that resource (similar to a try-with-resources).static <@NonNull T,@NonNull U>
@NonNull Single<T>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 aSingleSource
instance generated from that resource (similar to a try-with-resources).static <@NonNull T>
@NonNull Single<T>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 aSingle
that emits the results of a specified combiner function applied to nine items emitted by nine otherSingleSource
s.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 aSingle
that emits the results of a specified combiner function applied to eight items emitted by eight otherSingleSource
s.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 aSingle
that emits the results of a specified combiner function applied to seven items emitted by seven otherSingleSource
s.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 aSingle
that emits the results of a specified combiner function applied to six items emitted by six otherSingleSource
s.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 aSingle
that emits the results of a specified combiner function applied to five items emitted by five otherSingleSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@NonNull T4,@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 Function4<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? super @NonNull T4,? extends @NonNull R> zipper)
Returns aSingle
that emits the results of a specified combiner function applied to four items emitted by four otherSingleSource
s.static <@NonNull T1,@NonNull T2,@NonNull T3,@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 Function3<? super @NonNull T1,? super @NonNull T2,? super @NonNull T3,? extends @NonNull R> zipper)
Returns aSingle
that emits the results of a specified combiner function applied to three items emitted by three otherSingleSource
s.static <@NonNull T1,@NonNull T2,@NonNull R>
@NonNull Single<R>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 aSingle
that emits the results of a specified combiner function applied to two items emitted by two otherSingleSource
s.static <@NonNull T,@NonNull R>
@NonNull Single<R>zip(@NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources, @NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper)
Waits until allSingleSource
sources provided by theIterable
sequence 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.static <@NonNull T,@NonNull R>
@NonNull Single<R>zipArray(@NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper, @NonNull SingleSource<? extends @NonNull T>... sources)
Waits until allSingleSource
sources 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.<@NonNull U,@NonNull R>
@NonNull Single<R>zipWith(@NonNull SingleSource<@NonNull U> other, @NonNull BiFunction<? super @NonNull T,? super @NonNull U,? extends @NonNull R> zipper)
Returns aSingle
that emits the result of applying a specified function to the pair of items emitted by the currentSingle
and another specifiedSingleSource
.
-
-
-
Method Detail
-
amb
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> amb(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Runs multipleSingleSource
s and signals the events of the first one that signals (disposing the rest).- Scheduler:
amb
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- theIterable
sequence of sources. A subscription to each source will occur in the same order as in thisIterable
.- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- 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 multipleSingleSource
s and signals the events of the first one that signals (disposing the rest).- Scheduler:
ambArray
does 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
Single
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided by anIterable
sequence.- Type Parameters:
T
- the value type- Parameters:
sources
- theIterable
sequence ofSingleSource
instances- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- 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 theSingleSource
s provided by anObservableSource
sequence.- Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
sources
- theObservableSource
ofSingleSource
instances- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided by aPublisher
sequence.- Type Parameters:
T
- the value type- Parameters:
sources
- thePublisher
ofSingleSource
instances- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 2.0
-
concat
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concat(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int prefetch)
Concatenate the single values, in a non-overlapping fashion, of theSingleSource
s provided by aPublisher
sequence and prefetched by the specified amount.- Type Parameters:
T
- the value type- Parameters:
sources
- thePublisher
ofSingleSource
instancesprefetch
- the number ofSingleSource
s to prefetch from thePublisher
- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifprefetch
is 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 aFlowable
that emits the items emitted by twoSingleSource
s, one after the other.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be concatenatedsource2
- aSingleSource
to be concatenated- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
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 aFlowable
that emits the items emitted by threeSingleSource
s, one after the other.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be concatenatedsource2
- aSingleSource
to be concatenatedsource3
- aSingleSource
to be concatenated- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orsource3
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
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 aFlowable
that emits the items emitted by fourSingleSource
s, one after the other.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concat
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be concatenatedsource2
- aSingleSource
to be concatenatedsource3
- aSingleSource
to be concatenatedsource4
- aSingleSource
to be concatenated- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orsource4
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
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 theSingleSource
s provided in an array.- Type Parameters:
T
- the value type- Parameters:
sources
- the array ofSingleSource
instances- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- 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 theSingleSource
s provided in an array.- Type Parameters:
T
- the value type- Parameters:
sources
- the array ofSingleSource
instances- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- 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 ofSingleSource
eagerly into a single stream of values.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSource
s. The operator buffers the value emitted by theseSingleSource
s 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 ofSingleSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
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 ofSingleSource
eagerly into a single stream of values.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSource
s. The operator buffers the value emitted by theseSingleSource
s 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 ofSingleSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates theIterable
sequence ofSingleSource
s into a single sequence by subscribing to eachSingleSource
, one after the other, one at a time and delays any errors till the all innerSingleSource
s terminate as aFlowable
sequence.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- theIterable
sequence ofSingleSource
s- Returns:
- the new
Flowable
with the concatenating behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates thePublisher
sequence ofSingleSource
s 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 outerPublisher
terminate as aFlowable
sequence.- Backpressure:
concatDelayError
fully supports backpressure.- Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- thePublisher
sequence ofSingleSource
s- Returns:
- the new
Flowable
with the concatenating behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatDelayError
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Flowable<T> concatDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int prefetch)
Concatenates thePublisher
sequence ofSingleSource
s 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 outerPublisher
terminate as aFlowable
sequence.- Backpressure:
concatDelayError
fully supports backpressure.- Scheduler:
concatDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- thePublisher
sequence ofSingleSource
sprefetch
- The number of upstream items to prefetch so that fresh items are ready to be mapped when a previousSingleSource
terminates. The operator replenishes after half of the prefetch amount has been consumed and turned intoSingleSource
s.- Returns:
- the new
Flowable
with the concatenating behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifprefetch
is non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates anIterable
sequence ofSingleSource
s eagerly into a single stream of values.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the source
SingleSource
s. The operator buffers the values emitted by theseSingleSource
s 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
- anIterable
sequence ofSingleSource
that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates anIterable
sequence ofSingleSource
s 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
SingleSource
s. The operator buffers the values emitted by theseSingleSource
s 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
- anIterable
sequence ofSingleSource
that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running innerSingleSource
s;Integer.MAX_VALUE
is interpreted as all innerSingleSource
s can be active at the same time- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 3.0.0
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates aPublisher
sequence ofSingleSource
s eagerly into a single stream of values.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
SingleSource
s as they are observed. The operator buffers the values emitted by theseSingleSource
s and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is 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 ofSingleSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
-
concatEager
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEager(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofSingleSource
s eagerly into a single stream of values and runs a limited number of those innerSingleSource
s at once.Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source
SingleSource
s as they are observed. The operator buffers the values emitted by theseSingleSource
s and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is 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 ofSingleSource
s that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running innerSingleSource
s;Integer.MAX_VALUE
is interpreted as all innerSingleSource
s can be active at the same time- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates anIterable
sequence ofSingleSource
s 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
SingleSource
s. The operator buffers the values emitted by theseSingleSource
s 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
- anIterable
sequence ofSingleSource
that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates anIterable
sequence ofSingleSource
s 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
SingleSource
s. The operator buffers the values emitted by theseSingleSource
s 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
- anIterable
sequence ofSingleSource
that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running innerSingleSource
s;Integer.MAX_VALUE
is interpreted as all innerSingleSource
s can be active at the same time- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is non-positive- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Concatenates aPublisher
sequence ofSingleSource
s 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
SingleSource
s as they are observed. The operator buffers the values emitted by theseSingleSource
s and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is 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 ofSingleSource
s that need to be eagerly concatenated- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
-
concatEagerDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources, int maxConcurrency)
Concatenates aPublisher
sequence ofSingleSource
s eagerly into a single stream of values, running at most the specified number of those innerSingleSource
s 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
SingleSource
s as they are observed. The operator buffers the values emitted by theseSingleSource
s and then drains them in order, each one after the previous one succeeds.- Backpressure:
- Backpressure is honored towards the downstream and the outer
Publisher
is 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 ofSingleSource
s that need to be eagerly concatenatedmaxConcurrency
- the number of innerSingleSource
s to run at once- Returns:
- the new
Flowable
instance with the specified concatenation behavior - Throws:
java.lang.NullPointerException
- ifsources
isnull
java.lang.IllegalArgumentException
- ifmaxConcurrency
is 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
SingleObserver
subscribes to the returnedSingle
, the providedSingleOnSubscribe
callback is invoked with a fresh instance of aSingleEmitter
that will interact only with that specificSingleObserver
. If thisSingleObserver
disposes the flow (makingSingleEmitter.isDisposed()
returntrue
), other observers subscribed to the same returnedSingle
are not affected.- Scheduler:
create
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
source
- the emitter that is called when aSingleObserver
subscribes to the returnedSingle
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
- See Also:
SingleOnSubscribe
,Cancellable
-
defer
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> defer(@NonNull @NonNull Supplier<? extends @NonNull SingleSource<? extends @NonNull T>> supplier)
Calls aSupplier
for each individualSingleObserver
to return the actualSingleSource
to be subscribed to.- Scheduler:
defer
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
supplier
- theSupplier
that is called for each individualSingleObserver
and returns aSingleSource
instance to subscribe to- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> error(@NonNull @NonNull Supplier<? extends @NonNull java.lang.Throwable> supplier)
Signals aThrowable
returned by the callback function for each individualSingleObserver
.- Scheduler:
error
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
supplier
- theSupplier
that is called for each individualSingleObserver
and returns aThrowable
instance to be emitted.- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
-
error
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> error(@NonNull @NonNull java.lang.Throwable throwable)
Returns aSingle
that invokes a subscriber'sonError
method when the subscriber subscribes to it.- Scheduler:
error
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of the item (ostensibly) emitted by theSingle
- Parameters:
throwable
- the particularThrowable
to pass toonError
- Returns:
- the new
Single
that invokes the subscriber'sonError
method when the subscriber subscribes to it - Throws:
java.lang.NullPointerException
- ifthrowable
isnull
- See Also:
- ReactiveX operators documentation: Throw
-
fromCallable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromCallable(@NonNull @NonNull java.util.concurrent.Callable<? extends @NonNull T> callable)
Returns aSingle
that invokes the givenCallable
for each incomingSingleObserver
and emits its value or exception to them.Allows you to defer execution of passed function until
SingleObserver
subscribes to theSingle
. It makes passed function "lazy". Result of the function invocation will be emitted by theSingle
.- Scheduler:
fromCallable
does not operate by default on a particularScheduler
.- Error handling:
- If the
Callable
throws an exception, the respectiveThrowable
is delivered to the downstream viaSingleObserver.onError(Throwable)
, except when the downstream has disposed thisSingle
source. In this latter case, theThrowable
is 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 whenSingleObserver
will subscribe to theSingle
.- Returns:
- the new
Single
whoseSingleObserver
s' subscriptions trigger an invocation of the given function. - Throws:
java.lang.NullPointerException
- ifcallable
isnull
- See Also:
defer(Supplier)
,fromSupplier(Supplier)
-
fromFuture
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> fromFuture(@NonNull @NonNull java.util.concurrent.Future<? extends @NonNull T> future)
Converts aFuture
into aSingle
and 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 theScheduler
supports it, interrupt the wait when the flow is disposed.A non-
null
value is then emitted viaonSuccess
or any exception is emitted viaonError
. If theFuture
completes withnull
, aNullPointerException
is signaled.- Scheduler:
fromFuture
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of object that theFuture
returns, and also the type of item to be emitted by the resultingSingle
- Parameters:
future
- the sourceFuture
- Returns:
- the new
Single
that emits the item from the sourceFuture
- Throws:
java.lang.NullPointerException
- iffuture
isnull
- See Also:
- ReactiveX operators documentation: From,
fromFuture(Future, long, TimeUnit)
,fromCompletionStage(CompletionStage)
-
fromFuture
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> fromFuture(@NonNull @NonNull java.util.concurrent.Future<? extends @NonNull T> future, long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Converts aFuture
into aSingle
and 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 theScheduler
supports it, interrupt the wait when the flow is disposed.A non-
null
value is then emitted viaonSuccess
or any exception is emitted viaonError
. If theFuture
completes withnull
, aNullPointerException
is signaled.- Scheduler:
fromFuture
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of object that theFuture
returns, and also the type of item to be emitted by the resultingSingle
- Parameters:
future
- the sourceFuture
timeout
- the maximum time to wait before callingget
unit
- theTimeUnit
of thetimeout
argument- Returns:
- the new
Single
that emits the item from the sourceFuture
- Throws:
java.lang.NullPointerException
- iffuture
orunit
isnull
- See Also:
- ReactiveX operators documentation: From
-
fromMaybe
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromMaybe(@NonNull @NonNull MaybeSource<@NonNull T> maybe)
Returns aSingle
instance that when subscribed to, subscribes to theMaybeSource
instance and emitsonSuccess
as a single item, turns anonComplete
intoNoSuchElementException
error signal or forwards theonError
signal.- Scheduler:
fromMaybe
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of theMaybeSource
element- Parameters:
maybe
- theMaybeSource
instance to subscribe to, notnull
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifmaybe
isnull
- 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 aSingle
instance that when subscribed to, subscribes to theMaybeSource
instance and emitsonSuccess
as a single item, emits thedefaultItem
for anonComplete
signal or forwards theonError
signal.- Scheduler:
fromMaybe
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of theMaybeSource
element- Parameters:
maybe
- theMaybeSource
instance to subscribe to, notnull
defaultItem
- the item to signal if the currentMaybeSource
is empty- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifmaybe
ordefaultItem
isnull
- Since:
- 3.0.0
-
fromPublisher
@BackpressureSupport(UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromPublisher(@NonNull @NonNull org.reactivestreams.Publisher<? extends @NonNull T> publisher)
Wraps a specificPublisher
into aSingle
and signals its single element or error.If the source
Publisher
is empty, aNoSuchElementException
is signaled. If the source has more than one element, anIndexOutOfBoundsException
is signaled.The
Publisher
must follow the Reactive Streams specification. Violating the specification may result in undefined behavior.If possible, use
create(SingleOnSubscribe)
to create a source-likeSingle
instead.Note that even though
Publisher
appears 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
publisher
is consumed in an unbounded fashion but will be cancelled if it produced more than one item. - Scheduler:
fromPublisher
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
publisher
- the sourcePublisher
instance, notnull
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifpublisher
isnull
- See Also:
create(SingleOnSubscribe)
-
fromObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromObservable(@NonNull @NonNull ObservableSource<? extends @NonNull T> observable)
Wraps a specificObservableSource
into aSingle
and signals its single element or error.If the
ObservableSource
is empty, aNoSuchElementException
is signaled. If the source has more than one element, anIndexOutOfBoundsException
is signaled.- Scheduler:
fromObservable
does 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
Single
instance - Throws:
java.lang.NullPointerException
- ifobservable
isnull
-
fromSupplier
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> fromSupplier(@NonNull @NonNull Supplier<? extends @NonNull T> supplier)
Returns aSingle
that invokes passed supplier and emits its result for each individualSingleObserver
that subscribes.Allows you to defer execution of passed function until a
SingleObserver
subscribes to theSingle
. It makes passed function "lazy". Result of the function invocation will be emitted by theSingle
.- Scheduler:
fromSupplier
does not operate by default on a particularScheduler
.- Error handling:
- If the
Supplier
throws an exception, the respectiveThrowable
is delivered to the downstream viaSingleObserver.onError(Throwable)
, except when the downstream has disposed thisSingle
source. In this latter case, theThrowable
is 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 whenSingleObserver
subscribes to theSingle
.- Returns:
- the new
Single
whoseSingleObserver
s' subscriptions trigger an invocation of the given function. - Throws:
java.lang.NullPointerException
- ifsupplier
isnull
- Since:
- 3.0.0
- See Also:
defer(Supplier)
,fromCallable(Callable)
-
just
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> just(@NonNull T item)
Returns aSingle
that emits a specified item.To convert any object into a
Single
that emits that object, pass that object into thejust
method.- Scheduler:
just
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the type of that item- Parameters:
item
- the item to emit- Returns:
- the new
Single
that emitsitem
- Throws:
java.lang.NullPointerException
- ifitem
isnull
- See Also:
- ReactiveX operators documentation: Just
-
merge
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Merges anIterable
sequence ofSingleSource
instances into a singleFlowable
sequence, running allSingleSource
s at once.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
SingleSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceSingleSource
s are disposed. If more than oneSingleSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has 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 sourceSingleSource
s have completed or failed with an error.
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- theIterable
sequence ofSingleSource
sources- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 2.0
- See Also:
mergeDelayError(Iterable)
-
merge
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> merge(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Merges a sequence ofSingleSource
instances emitted by aPublisher
into a singleFlowable
sequence, running allSingleSource
s at once.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
SingleSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceSingleSource
s are disposed. If more than oneSingleSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has 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 sourceSingleSource
s have completed or failed with an error.
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- thePublisher
emitting a sequence ofSingleSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 2.0
- See Also:
mergeDelayError(Publisher)
-
merge
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> merge(@NonNull @NonNull SingleSource<? extends SingleSource<? extends @NonNull T>> source)
Flattens aSingleSource
that emits aSingleSingle
into a singleSingle
that emits the item emitted by the nestedSingleSource
, without any transformation.- Scheduler:
merge
does not operate by default on a particularScheduler
.- The resulting
Single
emits the outer source's or the innerSingleSource
'sThrowable
as is. Unlike the othermerge()
operators, this operator won't and can't produce aCompositeException
because there is only one possibility for the outer or the innerSingleSource
to emit anonError
signal. 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
- aSingle
that emits aSingle
- Returns:
- the new
Single
that emits the item that is the result of flattening theSingle
emitted bysource
- Throws:
java.lang.NullPointerException
- ifsource
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
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 twoSingleSource
s into oneFlowable
sequence, without any transformation.You can combine items emitted by multiple
SingleSource
s so that they appear as a singleFlowable
, by using themerge
method.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
SingleSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceSingleSource
s are disposed. If more than oneSingleSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has 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 sourceSingleSource
s have completed or failed with an error.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be mergedsource2
- aSingleSource
to be merged- Returns:
- the new
Flowable
that emits all of the items emitted by the sourceSingleSource
s - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- See Also:
- ReactiveX operators documentation: Merge,
mergeDelayError(SingleSource, SingleSource)
-
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 threeSingleSource
s into oneFlowable
sequence, without any transformation.You can combine items emitted by multiple
SingleSource
s so that they appear as a singleFlowable
, by themerge
method.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
SingleSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceSingleSource
s are disposed. If more than oneSingleSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has 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 sourceSingleSource
s have completed or failed with an error.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be mergedsource2
- aSingleSource
to be mergedsource3
- aSingleSource
to be merged- Returns:
- the new
Flowable
that emits all of the items emitted by the sourceSingleSource
s - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orsource3
isnull
- See Also:
- ReactiveX operators documentation: Merge,
mergeDelayError(SingleSource, SingleSource, SingleSource)
-
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 fourSingleSource
s into oneFlowable
sequence, without any transformation.You can combine items emitted by multiple
SingleSource
s so that they appear as a singleFlowable
, by themerge
method.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
merge
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
SingleSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceSingleSource
s are disposed. If more than oneSingleSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has 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 sourceSingleSource
s have completed or failed with an error.
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be mergedsource2
- aSingleSource
to be mergedsource3
- aSingleSource
to be mergedsource4
- aSingleSource
to be merged- Returns:
- the new
Flowable
that emits all of the items emitted by the sourceSingleSource
s - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orsource4
isnull
- See Also:
- ReactiveX operators documentation: Merge,
mergeDelayError(SingleSource, SingleSource, SingleSource, SingleSource)
-
mergeArray
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T> @NonNull Flowable<T> mergeArray(SingleSource<? extends @NonNull T>... sources)
Merges an array ofSingleSource
instances into a singleFlowable
sequence, running allSingleSource
s at once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArray
does not operate by default on a particularScheduler
.- Error handling:
- If any of the source
SingleSource
s signal aThrowable
viaonError
, the resultingFlowable
terminates with thatThrowable
and all other sourceSingleSource
s are disposed. If more than oneSingleSource
signals an error, the resultingFlowable
may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with aCompositeException
containing two or more of the various error signals.Throwable
s that didn't make into the composite will be sent (individually) to the global error handler viaRxJavaPlugins.onError(Throwable)
method asUndeliverableException
errors. Similarly,Throwable
s signaled by source(s) after the returnedFlowable
has 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 sourceSingleSource
s have completed or failed with an error.
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- the array sequence ofSingleSource
sources- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
mergeArrayDelayError(SingleSource...)
-
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 ofSingleSource
s into oneFlowable
, in a way that allows a subscriber to receive all successfully emitted items from each of the sourceSingleSource
s without being interrupted by an error notification from one of them.This behaves like
merge(Publisher)
except that if any of the mergedSingleSource
s notify of an error viaonError
,mergeArrayDelayError
will refrain from propagating that error notification until all of the mergedSingleSource
s have finished emitting items.Even if multiple merged
SingleSource
s sendonError
notifications,mergeArrayDelayError
will only invoke theonError
method of its subscribers once.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
mergeArrayDelayError
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common element base type- Parameters:
sources
- the array ofSingleSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
mergeDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources)
Merges anIterable
sequence ofSingleSource
instances into oneFlowable
sequence, running allSingleSource
s at once and delaying any error(s) until all sources succeed or fail.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
History: 2.1.9 - experimental
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- theIterable
sequence ofSingleSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 2.2
- See Also:
merge(Iterable)
-
mergeDelayError
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> mergeDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Merges a sequence ofSingleSource
instances emitted by aPublisher
into aFlowable
sequence, running allSingleSource
s at once and delaying any error(s) until all sources succeed or fail.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
History: 2.1.9 - experimental
- Type Parameters:
T
- the common and resulting value type- Parameters:
sources
- theFlowable
sequence ofSingleSource
s- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 2.2
- See Also:
merge(Publisher)
-
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 twoSingleSource
s into oneFlowable
, without any transformation, delaying any error(s) until all sources succeed or fail.You can combine items emitted by multiple
SingleSource
s so that they appear as oneFlowable
, by using themergeDelayError
method.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
History: 2.1.9 - experimental
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be mergedsource2
- aSingleSource
to be merged- Returns:
- the new
Flowable
that emits all of the items emitted by the sourceSingleSource
s - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- Since:
- 2.2
- See Also:
- ReactiveX operators documentation: Merge,
merge(SingleSource, SingleSource)
-
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 twoSingleSource
s into oneFlowable
, without any transformation, delaying any error(s) until all sources succeed or fail.You can combine items emitted by multiple
SingleSource
s so that they appear as oneFlowable
, by themergeDelayError
method.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
History: 2.1.9 - experimental
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be mergedsource2
- aSingleSource
to be mergedsource3
- aSingleSource
to be merged- Returns:
- the new
Flowable
that emits all of the items emitted by the sourceSingleSource
s - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orsource3
isnull
- Since:
- 2.2
- See Also:
- ReactiveX operators documentation: Merge,
merge(SingleSource, SingleSource, SingleSource)
-
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 twoSingleSource
s into oneFlowable
, without any transformation, delaying any error(s) until all sources succeed or fail.You can combine items emitted by multiple
SingleSource
s so that they appear as oneFlowable
, by themergeDelayError
method.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
mergeDelayError
does not operate by default on a particularScheduler
.
History: 2.1.9 - experimental
- Type Parameters:
T
- the common value type- Parameters:
source1
- aSingleSource
to be mergedsource2
- aSingleSource
to be mergedsource3
- aSingleSource
to be mergedsource4
- aSingleSource
to be merged- Returns:
- the new
Flowable
that emits all of the items emitted by the sourceSingleSource
s - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orsource4
isnull
- Since:
- 2.2
- See Also:
- ReactiveX operators documentation: Merge,
merge(SingleSource, SingleSource, SingleSource, SingleSource)
-
never
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<T> never()
Returns a singleton instance of a never-signalingSingle
(only callsonSubscribe
).- Scheduler:
never
does 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<java.lang.Long> timer(long delay, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Signals success with 0L value after the given delay when aSingleObserver
subscribes.- Scheduler:
timer
operates by default on thecomputation
Scheduler
.
- Parameters:
delay
- the delay amountunit
- the time unit of the delay- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 2.0
-
timer
@CheckReturnValue @NonNull @SchedulerSupport("custom") public static @NonNull Single<java.lang.Long> timer(long delay, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Signals success with 0L value on the specifiedScheduler
after the given delay when aSingleObserver
subscribes.- Scheduler:
- you specify the
Scheduler
to signal on.
- Parameters:
delay
- the delay amountunit
- the time unit of the delayscheduler
- theScheduler
where the single 0L will be emitted- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
, or ifscheduler
isnull
- Since:
- 2.0
-
sequenceEqual
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<java.lang.Boolean> sequenceEqual(@NonNull @NonNull SingleSource<? extends @NonNull T> source1, @NonNull @NonNull SingleSource<? extends @NonNull T> source2)
Compares twoSingleSource
s and emitstrue
if they emit the same value (compared viaObject.equals(Object)
).- Scheduler:
sequenceEqual
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value type- Parameters:
source1
- the firstSingleSource
instancesource2
- the secondSingleSource
instance- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsource1
orsource2
isnull
- Since:
- 2.0
-
switchOnNext
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNext(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Switches betweenSingleSource
s emitted by the sourcePublisher
whenever a newSingleSource
is emitted, disposing the previously runningSingleSource
, exposing the success items as aFlowable
sequence.- Backpressure:
- The
sources
Publisher
is consumed in an unbounded manner (requestingLong.MAX_VALUE
). The returnedFlowable
respects the backpressure from the downstream. - Scheduler:
switchOnNext
does not operate by default on a particularScheduler
.- Error handling:
- The returned sequence fails with the first error signaled by the
sources
Publisher
or 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 theSingleSource
s- Parameters:
sources
- thePublisher
sequence of innerSingleSource
s to switch between- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
- See Also:
switchOnNextDelayError(Publisher)
, ReactiveX operators documentation: Switch
-
switchOnNextDelayError
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Flowable<T> switchOnNextDelayError(@NonNull @NonNull org.reactivestreams.Publisher<? extends SingleSource<? extends @NonNull T>> sources)
Switches betweenSingleSource
s emitted by the sourcePublisher
whenever a newSingleSource
is emitted, disposing the previously runningSingleSource
, exposing the success items as aFlowable
sequence and delaying all errors from all of them until all terminate.- Backpressure:
- The
sources
Publisher
is consumed in an unbounded manner (requestingLong.MAX_VALUE
). The returnedFlowable
respects the backpressure from the downstream. - Scheduler:
switchOnNextDelayError
does not operate by default on a particularScheduler
.- Error handling:
- The returned
Flowable
collects all errors emitted by either thesources
Publisher
or any innerSingleSource
and emits them as aCompositeException
when 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 theSingleSource
s- Parameters:
sources
- thePublisher
sequence of innerSingleSource
s to switch between- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifsources
isnull
- Since:
- 3.0.0
- See Also:
switchOnNext(Publisher)
, ReactiveX operators documentation: Switch
-
unsafeCreate
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> unsafeCreate(@NonNull @NonNull SingleSource<@NonNull T> onSubscribe)
Advanced use only: creates aSingle
instance without any safeguards by using a callback that is called with aSingleObserver
.- Scheduler:
unsafeCreate
does 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
Single
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
isnull
java.lang.IllegalArgumentException
- ifsource
is 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 aSingleSource
instance generated from that resource (similar to a try-with-resources).- Scheduler:
using
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of theSingleSource
generatedU
- the resource type- Parameters:
resourceSupplier
- theSupplier
called for eachSingleObserver
to generate a resource objectsourceSupplier
- the function called with the returned resource object fromresourceSupplier
and should return aSingleSource
instance to be run by the operatorresourceCleanup
- the consumer of the generated resource that is called exactly once for that particular resource when the generatedSingleSource
terminates (successfully or with an error) or gets disposed.- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifresourceSupplier
,sourceSupplier
andresourceCleanup
isnull
- 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 aSingleSource
instance generated from that resource (similar to a try-with-resources).- Scheduler:
using
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type of theSingleSource
generatedU
- the resource type- Parameters:
resourceSupplier
- theSupplier
called for eachSingleObserver
to generate a resource objectsourceSupplier
- the function called with the returned resource object fromresourceSupplier
and should return aSingleSource
instance to be run by the operatorresourceCleanup
- the consumer of the generated resource that is called exactly once for that particular resource when the generatedSingleSource
terminates (successfully or with an error) or gets disposed.eager
- Iftrue
then resource disposal will happen either on adispose()
call before the upstream is disposed or just before the emission of a terminal event (onSuccess
oronError
). Iffalse
the resource disposal will happen either on adispose()
call after the upstream is disposed or just after the emission of a terminal event (onSuccess
oronError
).- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifresourceSupplier
,sourceSupplier
orresourceCleanup
isnull
- Since:
- 2.0
-
wrap
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T> @NonNull Single<T> wrap(@NonNull @NonNull SingleSource<@NonNull T> source)
Wraps aSingleSource
instance into a newSingle
instance if not already aSingle
instance.- Scheduler:
wrap
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the value type- Parameters:
source
- the source to wrap- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsource
isnull
-
zip
@CheckReturnValue @NonNull @SchedulerSupport("none") public static <@NonNull T,@NonNull R> @NonNull Single<R> zip(@NonNull @NonNull java.lang.Iterable<? extends SingleSource<? extends @NonNull T>> sources, @NonNull @NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper)
Waits until allSingleSource
sources provided by theIterable
sequence 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
Iterable
ofSingleSource
s is empty aNoSuchElementException
error 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
SingleSources
signal an error, all otherSingleSource
s get disposed and the error emitted to downstream immediately.- Scheduler:
zip
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value typeR
- the result value type- Parameters:
sources
- theIterable
sequence ofSingleSource
instances. An empty sequence will result in anonError
signal ofNoSuchElementException
.zipper
- the function that receives an array with values from eachSingleSource
and should return a value to be emitted to downstream- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifzipper
orsources
isnull
- 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 aSingle
that emits the results of a specified combiner function applied to two items emitted by two otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
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 aSingle
that emits the results of a specified combiner function applied to three items emitted by three otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
source3
- a third sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
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 aSingle
that emits the results of a specified combiner function applied to four items emitted by four otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
source3
- a third sourceSingleSource
source4
- a fourth sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
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 aSingle
that emits the results of a specified combiner function applied to five items emitted by five otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
source3
- a third sourceSingleSource
source4
- a fourth sourceSingleSource
source5
- a fifth sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
source5
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
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 aSingle
that emits the results of a specified combiner function applied to six items emitted by six otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
source3
- a third sourceSingleSource
source4
- a fourth sourceSingleSource
source5
- a fifth sourceSingleSource
source6
- a sixth sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
source5
,source6
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
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 aSingle
that emits the results of a specified combiner function applied to seven items emitted by seven otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
source3
- a third sourceSingleSource
source4
- a fourth sourceSingleSource
source5
- a fifth sourceSingleSource
source6
- a sixth sourceSingleSource
source7
- a seventh sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
source5
,source6
,source7
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
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 aSingle
that emits the results of a specified combiner function applied to eight items emitted by eight otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
source3
- a third sourceSingleSource
source4
- a fourth sourceSingleSource
source5
- a fifth sourceSingleSource
source6
- a sixth sourceSingleSource
source7
- a seventh sourceSingleSource
source8
- an eighth sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
source5
,source6
,source7
,source8
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
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 aSingle
that emits the results of a specified combiner function applied to nine items emitted by nine otherSingleSource
s.- Scheduler:
zip
does 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 sourceSingleSource
source2
- a second sourceSingleSource
source3
- a third sourceSingleSource
source4
- a fourth sourceSingleSource
source5
- a fifth sourceSingleSource
source6
- a sixth sourceSingleSource
source7
- a seventh sourceSingleSource
source8
- an eighth sourceSingleSource
source9
- a ninth sourceSingleSource
zipper
- a function that, when applied to the item emitted by each of the sourceSingleSource
s, results in an item that will be emitted by the resultingSingle
- Returns:
- the new
Single
that emits the zipped results - Throws:
java.lang.NullPointerException
- ifsource1
,source2
,source3
,source4
source5
,source6
,source7
,source8
,source9
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
zipArray
@CheckReturnValue @NonNull @SchedulerSupport("none") @SafeVarargs public static <@NonNull T,@NonNull R> @NonNull Single<R> zipArray(@NonNull @NonNull Function<? super java.lang.Object[],? extends @NonNull R> zipper, @NonNull @NonNull SingleSource<? extends @NonNull T>... sources)
Waits until allSingleSource
sources 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
SingleSource
s is empty aNoSuchElementException
error 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
SingleSource
s signal an error, all otherSingleSource
s get disposed and the error emitted to downstream immediately.- Scheduler:
zipArray
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the common value typeR
- the result value type- Parameters:
sources
- the array ofSingleSource
instances. An empty sequence will result in anonError
signal ofNoSuchElementException
.zipper
- the function that receives an array with values from eachSingleSource
and should return a value to be emitted to downstream- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifzipper
orsources
isnull
- 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 otherSingleSource
whichever signals first.- Scheduler:
ambWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherSingleSource
to race for the first emission of success or error- Returns:
- the new
Single
instance. A subscription to this provided source will occur after subscribing to the current source. - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 2.0
-
hide
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> hide()
Hides the identity of the currentSingle
, including theDisposable
that is sent to the downstream viaonSubscribe()
.- Scheduler:
hide
does not operate by default on a particularScheduler
.
- Returns:
- the new
Single
instance - 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 aSingle
by applying a particularSingleTransformer
function to it.This method operates on the
Single
itself whereaslift(io.reactivex.rxjava3.core.SingleOperator<? extends R, ? super T>)
operates onSingleObserver
s.If the operator you are creating is designed to act on the individual item emitted by a
Single
, uselift(io.reactivex.rxjava3.core.SingleOperator<? extends R, ? super T>)
. If your operator is designed to transform the currentSingle
as a whole (for instance, by applying a particular set of existing RxJava operators to it) usecompose
.- Scheduler:
compose
does 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
Single
instance - Throws:
java.lang.NullPointerException
- iftransformer
isnull
- See Also:
- RxJava wiki: Implementing Your Own Operators
-
cache
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> cache()
Stores the success value or exception from the currentSingle
and replays it to lateSingleObserver
s.The returned
Single
subscribes to the currentSingle
when the firstSingleObserver
subscribes.- Scheduler:
cache
does not operate by default on a particularScheduler
.
- Returns:
- the new
Single
instance - Since:
- 2.0
-
cast
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Single<U> cast(@NonNull @NonNull java.lang.Class<? extends @NonNull U> clazz)
Casts the success value of the currentSingle
into the target type or signals aClassCastException
if not compatible.- Scheduler:
cast
does 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
Single
instance - Throws:
java.lang.NullPointerException
- ifclazz
isnull
- 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 aSingle
that 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:
concatMap
does 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
Single
returned frommapper
when applied to the item emitted by the currentSingle
- Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
concatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable concatMapCompletable(@NonNull @NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that 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:
concatMapCompletable
does 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
Completable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
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 aMaybe
that 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:
concatMapMaybe
does 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
Maybe
returned frommapper
when applied to the item emitted by the currentSingle
- Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
concatWith
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> concatWith(@NonNull @NonNull SingleSource<? extends @NonNull T> other)
Returns aFlowable
that emits the item emitted by the currentSingle
, then the item emitted by the specifiedSingleSource
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
concatWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- aSingleSource
to be concatenated after the current- Returns:
- the new
Flowable
that emits the item emitted by the currentSingle
, followed by the item emitted byother
- Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: Concat
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Delays the emission of the success signal from the currentSingle
by the specified amount. An error signal will not be delayed.- Scheduler:
delay
operates by default on thecomputation
Scheduler
.
- Parameters:
time
- the amount of time the success signal should be delayed forunit
- the time unit- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 2.0
- See Also:
delay(long, TimeUnit, boolean)
-
delay
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, boolean delayError)
Delays the emission of the success or error signal from the currentSingle
by the specified amount.- Scheduler:
delay
operates by default on thecomputation
Scheduler
.
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
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 2.2
-
delay
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Single<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Delays the emission of the success signal from the currentSingle
by the specified amount. An error signal will not be delayed.- Scheduler:
- you specify the
Scheduler
where 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
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
, or ifscheduler
isnull
- Since:
- 2.0
- See Also:
delay(long, TimeUnit, Scheduler, boolean)
-
delay
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> delay(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler, boolean delayError)
Delays the emission of the success or error signal from the currentSingle
by the specified amount.- Scheduler:
- you specify the
Scheduler
where 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
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
, or ifscheduler
isnull
- Since:
- 2.2
-
delaySubscription
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> delaySubscription(@NonNull @NonNull CompletableSource subscriptionIndicator)
Delays the actual subscription to the currentSingle
until the given otherCompletableSource
completes.If the delaying source signals an error, that error is re-emitted and no subscription to the current
Single
happens.- Scheduler:
delaySubscription
does not operate by default on a particularScheduler
.
- Parameters:
subscriptionIndicator
- theCompletableSource
that has to complete before the subscription to the currentSingle
happens- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsubscriptionIndicator
isnull
- 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 currentSingle
until the given otherSingleSource
signals success.If the delaying source signals an error, that error is re-emitted and no subscription to the current
Single
happens.- Scheduler:
delaySubscription
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the element type of the other source- Parameters:
subscriptionIndicator
- theSingleSource
that has to complete before the subscription to the currentSingle
happens- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsubscriptionIndicator
isnull
- 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 currentSingle
until the given otherObservableSource
signals its first value or completes.If the delaying source signals an error, that error is re-emitted and no subscription to the current
Single
happens.- Scheduler:
delaySubscription
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the element type of the other source- Parameters:
subscriptionIndicator
- theObservableSource
that has to signal a value or complete before the subscription to the currentSingle
happens- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsubscriptionIndicator
isnull
- Since:
- 2.0
-
delaySubscription
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Single<T> delaySubscription(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull U> subscriptionIndicator)
Delays the actual subscription to the currentSingle
until the given otherPublisher
signals its first value or completes.If the delaying source signals an error, that error is re-emitted and no subscription to the current
Single
happens.The other source is consumed in an unbounded manner (requesting
Long.MAX_VALUE
from it).- Backpressure:
- The
other
publisher is consumed in an unbounded fashion but will be cancelled after the first item it produced. - Scheduler:
delaySubscription
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the element type of the other source- Parameters:
subscriptionIndicator
- thePublisher
that has to signal a value or complete before the subscription to the currentSingle
happens- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifsubscriptionIndicator
isnull
- Since:
- 2.0
-
delaySubscription
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> delaySubscription(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Delays the actual subscription to the currentSingle
until the given time delay elapsed.- Scheduler:
delaySubscription
does by default subscribe to the currentSingle
on thecomputation
Scheduler
after the delay.
- Parameters:
time
- the time amount to wait with the subscriptionunit
- the time unit of the waiting- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 2.0
-
delaySubscription
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Single<T> delaySubscription(long time, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Delays the actual subscription to the currentSingle
until the given time delay elapsed.- Scheduler:
delaySubscription
does by default subscribe to the currentSingle
on theScheduler
you provided, after the delay.
- Parameters:
time
- the time amount to wait with the subscriptionunit
- the time unit of the waitingscheduler
- theScheduler
to wait on and subscribe on to the currentSingle
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- 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 theNotification
success value of the currentSingle
back into normalonSuccess
,onError
oronComplete
signals as aMaybe
source.The intended use of the
selector
function 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:
dematerialize
does 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 aNotification
instance.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifselector
isnull
- Since:
- 3.0.0
- See Also:
materialize()
-
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
doAfterSuccess
action is shared between subscriptions and as such should be thread-safe.- Scheduler:
doAfterSuccess
does not operate by default on a particularScheduler
.
History: 2.0.1 - experimental
- Parameters:
onAfterSuccess
- theConsumer
that will be called after emitting an item from upstream to the downstream- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonAfterSuccess
isnull
- Since:
- 2.1
-
doAfterTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doAfterTerminate(@NonNull @NonNull Action onAfterTerminate)
Registers anAction
to be called after thisSingle
invokes eitheronSuccess
oronError
.Note that the
doAfterTerminate
action is shared between subscriptions and as such should be thread-safe.- Scheduler:
doAfterTerminate
does not operate by default on a particularScheduler
.
History: 2.0.6 - experimental
- Parameters:
onAfterTerminate
- anAction
to be invoked when the currentSingle
finishes- Returns:
- the new
Single
that emits the same items as the currentSingle
, then invokes theAction
- Throws:
java.lang.NullPointerException
- ifonAfterTerminate
isnull
- Since:
- 2.1
- See Also:
- ReactiveX operators documentation: Do
-
doFinally
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doFinally(@NonNull @NonNull Action onFinally)
Calls the specified action after thisSingle
signalsonSuccess
oronError
or gets disposed by the downstream.In case of a race between a terminal event and a dispose call, the provided
onFinally
action is executed once per subscription.Note that the
onFinally
action is shared between subscriptions and as such should be thread-safe.- Scheduler:
doFinally
does not operate by default on a particularScheduler
.
History: 2.0.1 - experimental
- Parameters:
onFinally
- the action called when thisSingle
terminates or gets disposed- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonFinally
isnull
- 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 appropriateonXXX
method (shared between allSingleObserver
s) for the lifecycle events of the sequence (subscription, disposal).- Scheduler:
doOnLifecycle
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- aConsumer
called with theDisposable
sent viaSingleObserver.onSubscribe(Disposable)
onDispose
- called when the downstream disposes theDisposable
viadispose()
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
oronDispose
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Do
-
doOnSubscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnSubscribe(@NonNull @NonNull Consumer<? super Disposable> onSubscribe)
Calls the shared consumer with theDisposable
sent through theonSubscribe
for eachSingleObserver
that subscribes to the currentSingle
.- Scheduler:
doOnSubscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSubscribe
- the consumer called with theDisposable
sent viaonSubscribe
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonSubscribe
isnull
- Since:
- 2.0
-
doOnTerminate
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnTerminate(@NonNull @NonNull Action onTerminate)
Returns aSingle
instance that calls the givenonTerminate
callback just before thisSingle
completes normally or with an exception.This differs from
doAfterTerminate
in that this happens before theonSuccess
oronError
notification.- Scheduler:
doOnTerminate
does not operate by default on a particularScheduler
.
History: 2.2.7 - experimental
- Parameters:
onTerminate
- the action to invoke when the consumer callsonSuccess
oronError
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonTerminate
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Do,
doOnTerminate(Action)
-
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 viaonSuccess
for eachSingleObserver
that subscribes to the currentSingle
.- Scheduler:
doOnSuccess
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- the consumer called with the success value ofonSuccess
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonSuccess
isnull
- Since:
- 2.0
-
doOnEvent
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnEvent(@NonNull @NonNull BiConsumer<? super @NonNull T,? super java.lang.Throwable> onEvent)
Calls the shared consumer with the error sent viaonError
or the value viaonSuccess
for eachSingleObserver
that subscribes to the currentSingle
.- Scheduler:
doOnEvent
does not operate by default on a particularScheduler
.
- Parameters:
onEvent
- the consumer called with the success value of onEvent- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonEvent
isnull
- Since:
- 2.0
-
doOnError
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnError(@NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Calls the shared consumer with the error sent viaonError
for eachSingleObserver
that subscribes to the currentSingle
.- Scheduler:
doOnError
does not operate by default on a particularScheduler
.
- Parameters:
onError
- the consumer called with the success value ofonError
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonError
isnull
- Since:
- 2.0
-
doOnDispose
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> doOnDispose(@NonNull @NonNull Action onDispose)
Calls the sharedAction
if aSingleObserver
subscribed to the currentSingle
disposes the commonDisposable
it received viaonSubscribe
.- Scheduler:
doOnDispose
does not operate by default on a particularScheduler
.
- Parameters:
onDispose
- the action called when the subscription is disposed- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonDispose
isnull
- 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 theSingle
via a predicate function and emitting it if the predicate returnstrue
, completing otherwise.- Scheduler:
filter
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- a function that evaluates the item emitted by the currentSingle
, returningtrue
if it passes the filter- Returns:
- the new
Maybe
that emit the item emitted by the currentSingle
that the filter evaluates astrue
- Throws:
java.lang.NullPointerException
- ifpredicate
isnull
- See Also:
- ReactiveX operators documentation: Filter
-
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 aSingle
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns aSingleSource
.- Scheduler:
flatMap
does 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
Single
returned frommapper
when applied to the item emitted by the currentSingle
- Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
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 aSingle
that emits the results of a specified function to the pair of values emitted by the currentSingle
and a specified mappedSingleSource
.- Scheduler:
flatMap
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of items emitted by theSingleSource
returned by themapper
functionR
- the type of items emitted by the resultingSingle
- Parameters:
mapper
- a function that returns aSingleSource
for the item emitted by the currentSingle
combiner
- a function that combines one item emitted by each of the source and collectionSingleSource
and returns an item to be emitted by the resultingSingleSource
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifmapper
orcombiner
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
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 java.lang.Throwable,? extends SingleSource<? extends @NonNull R>> onErrorMapper)
Maps theonSuccess
oronError
signals of the currentSingle
into aSingleSource
and emits thatSingleSource
's signals.- Scheduler:
flatMap
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the result type- Parameters:
onSuccessMapper
- a function that returns aSingleSource
to merge for theonSuccess
item emitted by thisSingle
onErrorMapper
- a function that returns aSingleSource
to merge for anonError
notification from thisSingle
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifonSuccessMapper
oronErrorMapper
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
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 aMaybe
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns aMaybeSource
.- Scheduler:
flatMapMaybe
does 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
Maybe
returned frommapper
when applied to the item emitted by the currentSingle
- Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMapPublisher
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Flowable<R> flatMapPublisher(@NonNull @NonNull Function<? super @NonNull T,? extends org.reactivestreams.Publisher<? extends @NonNull R>> mapper)
Returns aFlowable
that emits items based on applying a specified function to the item emitted by the currentSingle
, where that function returns aPublisher
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer and thePublisher
returned by the mapper function is expected to honor it as well. - Scheduler:
flatMapPublisher
does 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
Flowable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flattenAsFlowable
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Flowable<U> flattenAsFlowable(@NonNull @NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentSingle
into anIterable
and emits its items as aFlowable
sequence.- Backpressure:
- The operator honors backpressure from downstream.
- Scheduler:
flattenAsFlowable
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of item emitted by the resultingIterable
- Parameters:
mapper
- a function that returns anIterable
sequence of values for when given an item emitted by the currentSingle
- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap,
flattenStreamAsFlowable(Function)
-
flattenAsObservable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Observable<U> flattenAsObservable(@NonNull @NonNull Function<? super @NonNull T,? extends java.lang.Iterable<? extends @NonNull U>> mapper)
Maps the success value of the currentSingle
into anIterable
and emits its items as anObservable
sequence.- Scheduler:
flattenAsObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of item emitted by the resultingIterable
- Parameters:
mapper
- a function that returns anIterable
sequence of values for when given an item emitted by the currentSingle
- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap,
flattenStreamAsObservable(Function)
-
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 anObservable
that is based on applying a specified function to the item emitted by the currentSingle
, where that function returns anObservableSource
.- Scheduler:
flatMapObservable
does 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
Observable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: FlatMap
-
flatMapCompletable
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Completable flatMapCompletable(@NonNull @NonNull Function<? super @NonNull T,? extends CompletableSource> mapper)
Returns aCompletable
that completes based on applying a specified function to the item emitted by the currentSingle
, where that function returns aCompletableSource
.- Scheduler:
flatMapCompletable
does 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
Completable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 2.0
- See Also:
- ReactiveX operators documentation: FlatMap
-
blockingGet
@CheckReturnValue @SchedulerSupport("none") @NonNull public final T blockingGet()
Waits in a blocking fashion until the currentSingle
signals a success value (which is returned) or an exception (which is propagated).- Scheduler:
blockingGet
does not operate by default on a particularScheduler
.- Error handling:
- If the source signals an error, the operator wraps a checked
Exception
intoRuntimeException
and throws that. Otherwise,RuntimeException
s andError
s are rethrown as they are.
- Returns:
- the success value
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe()
Subscribes to the currentSingle
and blocks the current thread until it terminates.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If the current
Single
signals an error, theThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, anInterruptedException
is routed to the same global error handler.
- Since:
- 3.0.0
- See Also:
blockingSubscribe(Consumer)
,blockingSubscribe(Consumer, Consumer)
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to the currentSingle
and calls givenonSuccess
callback on the current thread when it completes normally.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If either the current
Single
signals an error oronSuccess
throws, the respectiveThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, anInterruptedException
is routed to the same global error handler.
- Parameters:
onSuccess
- theConsumer
to call if the currentSingle
succeeds- Throws:
java.lang.NullPointerException
- ifonSuccess
isnull
- Since:
- 3.0.0
- See Also:
blockingSubscribe(Consumer, Consumer)
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to the currentSingle
and calls the appropriate callback on the current thread when it terminates.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- If either
onSuccess
oronError
throw, theThrowable
is routed to the global error handler viaRxJavaPlugins.onError(Throwable)
. If the current thread is interrupted, theonError
consumer is called with anInterruptedException
.
- Parameters:
onSuccess
- theConsumer
to call if the currentSingle
succeedsonError
- theConsumer
to call if the currentSingle
signals an error- Throws:
java.lang.NullPointerException
- ifonSuccess
oronError
isnull
- Since:
- 3.0.0
-
blockingSubscribe
@SchedulerSupport("none") public final void blockingSubscribe(@NonNull @NonNull SingleObserver<? super @NonNull T> observer)
Subscribes to the currentSingle
and calls the appropriateSingleObserver
method on the current thread.- Scheduler:
blockingSubscribe
does not operate by default on a particularScheduler
.- Error handling:
- An
onError
signal is delivered to theSingleObserver.onError(Throwable)
method. If any of theSingleObserver
's methods throw, theRuntimeException
is propagated to the caller of this method. If the current thread is interrupted, anInterruptedException
is delivered toobserver.onError
.
- Parameters:
observer
- theSingleObserver
to call methods on the current thread- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- 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 aSingle
which, when subscribed to, invokes theapply(SingleObserver)
method of the providedSingleOperator
for each individual downstreamSingle
and allows the insertion of a custom operator by accessing the downstream'sSingleObserver
during 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
SingleObserver
will wrap the downstream'sSingleObserver
and forwards theonSuccess
andonError
events 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 ofdispose
andisDisposed
that 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 abstractSingle
class and creating aSingleTransformer
with it is recommended.Note also that it is not possible to stop the subscription phase in
lift()
as theapply()
method requires a non-null
SingleObserver
instance 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 aSingleObserver
that should immediately dispose the upstream'sDisposable
in itsonSubscribe
method. Again, using aSingleTransformer
and extending theSingle
is a better option assubscribeActual(io.reactivex.rxjava3.core.SingleObserver<? super T>)
can decide to not subscribe to its upstream after all.- Scheduler:
lift
does not operate by default on a particularScheduler
, however, theSingleOperator
may use aScheduler
to support its own asynchronous behavior.
- Type Parameters:
R
- the output value type- Parameters:
lift
- theSingleOperator
that receives the downstream'sSingleObserver
and should return aSingleObserver
with custom behavior to be used as the consumer for the currentSingle
.- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- iflift
isnull
- See Also:
- RxJava wiki: Writing operators,
compose(SingleTransformer)
-
map
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull R> @NonNull Single<R> map(@NonNull @NonNull Function<? super @NonNull T,? extends @NonNull R> mapper)
Returns aSingle
that applies a specified function to the item emitted by the currentSingle
and emits the result of this function application.- Scheduler:
map
does 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
Single
that emits the item from the currentSingle
, transformed by the specified function - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- See Also:
- ReactiveX operators documentation: Map
-
materialize
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<Notification<T>> materialize()
Maps the signal types of thisSingle
into aNotification
of the same kind and emits it as a single success value to downstream.- Scheduler:
materialize
does not operate by default on a particularScheduler
.
History: 2.2.4 - experimental
- Returns:
- the new
Single
instance - Since:
- 3.0.0
- See Also:
dematerialize(Function)
-
contains
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<java.lang.Boolean> contains(@NonNull @NonNull java.lang.Object item)
Signalstrue
if the currentSingle
signals a success value that isObject.equals(Object)
with the value provided.- Scheduler:
contains
does not operate by default on a particularScheduler
.
- Parameters:
item
- the value to compare against the success value of thisSingle
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifitem
isnull
- Since:
- 2.0
-
contains
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<java.lang.Boolean> contains(@NonNull @NonNull java.lang.Object item, @NonNull @NonNull BiPredicate<java.lang.Object,java.lang.Object> comparer)
Signalstrue
if the currentSingle
signals a success value that is equal with the value provided by calling aBiPredicate
.- Scheduler:
contains
does not operate by default on a particularScheduler
.
- Parameters:
item
- the value to compare against the success value of thisSingle
comparer
- the function that receives the success value of thisSingle
, the value provided and should returntrue
if they are considered equal- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifitem
orcomparer
isnull
- Since:
- 2.0
-
mergeWith
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> mergeWith(@NonNull @NonNull SingleSource<? extends @NonNull T> other)
Flattens thisSingle
and anotherSingleSource
into oneFlowable
, without any transformation.You can combine items emitted by multiple
SingleSource
s so that they appear as oneFlowable
, by using themergeWith
method.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
mergeWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- aSingleSource
to be merged- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: Merge
-
ofType
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull U> @NonNull Maybe<U> ofType(@NonNull @NonNull java.lang.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:
ofType
does 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
Maybe
instance - Throws:
java.lang.NullPointerException
- ifclazz
isnull
- Since:
- 3.0.0
- See Also:
- ReactiveX operators documentation: Filter
-
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 currentSingle
on the specifiedScheduler
, asynchronously.- Scheduler:
- you specify which
Scheduler
this operator will use.
- Parameters:
scheduler
- theScheduler
to notify subscribers on- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- See Also:
- ReactiveX operators documentation: ObserveOn,
RxJava Threading Examples,
subscribeOn(io.reactivex.rxjava3.core.Scheduler)
-
onErrorReturn
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> onErrorReturn(@NonNull @NonNull Function<java.lang.Throwable,? extends @NonNull T> itemSupplier)
Ends the flow with a success item returned by a function for theThrowable
error signaled by the currentSingle
instead of signaling the error viaonError
.By default, when a
Single
encounters an error that prevents it from emitting the expected item to its subscriber, theSingle
invokes its subscriber'sSingleObserver.onError(java.lang.Throwable)
method, and then quits without invoking any more of its observer's methods. TheonErrorReturn
method changes this behavior. If you pass a function (resumeFunction
) to aSingle
'sonErrorReturn
method, if the originalSingle
encounters an error, instead of invoking its observer'sSingleObserver.onError(java.lang.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:
onErrorReturn
does not operate by default on a particularScheduler
.
- Parameters:
itemSupplier
- a function that returns an item that the newSingle
will emit if the currentSingle
encounters an error- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifitemSupplier
isnull
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorReturnItem
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> onErrorReturnItem(@NonNull @NonNull T item)
Signals the specified value as success in case the currentSingle
signals an error.- Scheduler:
onErrorReturnItem
does not operate by default on a particularScheduler
.
- Parameters:
item
- the value to signal if the currentSingle
fails- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifitem
isnull
- 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 givenSingleSource
when the currentSingle
fails instead of signaling the error viaonError
.By default, when a
Single
encounters an error that prevents it from emitting the expected item to itsSingleObserver
, theSingle
invokes itsSingleObserver
'sonError
method, and then quits without invoking any more of itsSingleObserver
's methods. TheonErrorResumeWith
method changes this behavior. If you pass anotherSingle
(resumeSingleInCaseOfError
) to aSingle
'sonErrorResumeWith
method, if the originalSingle
encounters an error, instead of invoking itsSingleObserver
'sonError
method, it will instead relinquish control toresumeSingleInCaseOfError
which will invoke theSingleObserver
'sonSuccess
method if it is able to do so. In such a case, because noSingle
necessarily invokesonError
, theSingleObserver
may 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:
onErrorResumeWith
does not operate by default on a particularScheduler
.
- Parameters:
fallback
- aSingle
that will take control if sourceSingle
encounters an error.- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- iffallback
isnull
- See Also:
- ReactiveX operators documentation: Catch
-
onErrorComplete
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> onErrorComplete()
Returns aMaybe
instance that if the currentSingle
emits an error, it will emit anonComplete
and swallow the throwable.- Scheduler:
onErrorComplete
does not operate by default on a particularScheduler
.
- Returns:
- the new
Maybe
instance - Since:
- 3.0.0
-
onErrorComplete
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Maybe<T> onErrorComplete(@NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Returns aMaybe
instance that if thisSingle
emits an error and the predicate returnstrue
, it will emit anonComplete
and swallow the throwable.- Scheduler:
onErrorComplete
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- the predicate to call when anThrowable
is emitted which should returntrue
if theThrowable
should be swallowed and replaced with anonComplete
.- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
- Since:
- 3.0.0
-
onErrorResumeNext
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> onErrorResumeNext(@NonNull @NonNull Function<? super java.lang.Throwable,? extends SingleSource<? extends @NonNull T>> fallbackSupplier)
Resumes the flow with aSingleSource
returned for the failureThrowable
of the currentSingle
by a function instead of signaling the error viaonError
.By default, when a
Single
encounters an error that prevents it from emitting the expected item to itsSingleObserver
, theSingle
invokes itsSingleObserver
'sonError
method, and then quits without invoking any more of itsSingleObserver
's methods. TheonErrorResumeNext
method changes this behavior. If you pass a function that will return anotherSingle
(resumeFunctionInCaseOfError
) to aSingle
'sonErrorResumeNext
method, if the originalSingle
encounters an error, instead of invoking itsSingleObserver
'sonError
method, it will instead relinquish control toresumeSingleInCaseOfError
which will invoke theSingleObserver
'sonSuccess
method if it is able to do so. In such a case, because noSingle
necessarily invokesonError
, theSingleObserver
may 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:
onErrorResumeNext
does not operate by default on a particularScheduler
.
- Parameters:
fallbackSupplier
- a function that returns aSingleSource
that will take control if sourceSingle
encounters an error.- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- iffallbackSupplier
isnull
- Since:
- .20
- See Also:
- ReactiveX operators documentation: Catch
-
onTerminateDetach
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> onTerminateDetach()
Nulls out references to the upstream producer and downstreamSingleObserver
if the sequence is terminated or downstream callsdispose()
.- Scheduler:
onTerminateDetach
does not operate by default on a particularScheduler
.
History: 2.1.5 - experimental
- Returns:
- the new
Single
whichnull
s out references to the upstream producer and downstreamSingleObserver
if 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 currentSingle
and emits each success value as aFlowable
sequence.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
repeat
does not operate by default on a particularScheduler
.
- Returns:
- the new
Flowable
instance - Since:
- 2.0
-
repeat
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeat(long times)
Re-subscribes to the currentSingle
at most the given number of times and emits each success value as aFlowable
sequence.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
repeat
does not operate by default on a particularScheduler
.
- Parameters:
times
- the number of times to re-subscribe to the currentSingle
- Returns:
- the new
Flowable
instance - Throws:
java.lang.IllegalArgumentException
- iftimes
is negative- Since:
- 2.0
-
repeatWhen
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatWhen(@NonNull @NonNull Function<? super Flowable<java.lang.Object>,? extends org.reactivestreams.Publisher<?>> handler)
Re-subscribes to the currentSingle
if thePublisher
returned by the handler function signals a value in response to a value signaled through theFlowable
the handler receives.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. ThePublisher
returned by the handler function is expected to honor backpressure as well. - Scheduler:
repeatWhen
does not operate by default on a particularScheduler
.
- Parameters:
handler
- the function that is called with aFlowable
that signals a value when theSingle
signaled a success value and returns aPublisher
that has to signal a value to trigger a resubscription to the currentSingle
, otherwise the terminal signal of thePublisher
will be the terminal signal of the sequence as well.- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifhandler
isnull
- Since:
- 2.0
-
repeatUntil
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> repeatUntil(@NonNull @NonNull BooleanSupplier stop)
Re-subscribes to the currentSingle
until the givenBooleanSupplier
returnstrue
and emits the success items as aFlowable
sequence.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
repeatUntil
does not operate by default on a particularScheduler
.
- Parameters:
stop
- theBooleanSupplier
called after the currentSingle
succeeds and if returnsfalse
, theSingle
is re-subscribed; otherwise the sequence completes.- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifstop
isnull
- Since:
- 2.0
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry()
Repeatedly re-subscribes to the currentSingle
indefinitely if it fails with anonError
.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Returns:
- the new
Single
instance - 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 currentSingle
if it fails with anonError
.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
times
- the number of times to resubscribe if the currentSingle
fails- Returns:
- the new
Single
instance - Throws:
java.lang.IllegalArgumentException
- iftimes
is negative- Since:
- 2.0
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry(@NonNull @NonNull BiPredicate<? super java.lang.Integer,? super java.lang.Throwable> predicate)
Re-subscribe to the currentSingle
if the given predicate returnstrue
when theSingle
fails with anonError
.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- the predicate called with the resubscription count and the failureThrowable
and should returntrue
if a resubscription should happen- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
- Since:
- 2.0
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry(long times, @NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Repeatedly re-subscribe at most times or until the predicate returnsfalse
, whichever happens first if it fails with anonError
.- Scheduler:
retry
does not operate by default on a particularScheduler
.
History: 2.1.8 - experimental
- Parameters:
times
- the number of times to resubscribe if the currentSingle
failspredicate
- the predicate called with the failureThrowable
and should returntrue
if a resubscription should happen- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
java.lang.IllegalArgumentException
- iftimes
is negative- Since:
- 2.2
-
retry
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retry(@NonNull @NonNull Predicate<? super java.lang.Throwable> predicate)
Re-subscribe to the currentSingle
if the given predicate returnstrue
when theSingle
fails with anonError
.- Scheduler:
retry
does not operate by default on a particularScheduler
.
- Parameters:
predicate
- the predicate called with the failureThrowable
and should returntrue
if a resubscription should happen- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifpredicate
isnull
- 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:
retryUntil
does not operate by default on a particularScheduler
.
- Parameters:
stop
- the function that should returntrue
to stop retrying- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifstop
isnull
- Since:
- 3.0.0
-
retryWhen
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Single<T> retryWhen(@NonNull @NonNull Function<? super Flowable<java.lang.Throwable>,? extends org.reactivestreams.Publisher<?>> handler)
Re-subscribes to the currentSingle
if and when thePublisher
returned by the handler function signals a value.If the
Publisher
signals anonComplete
, the resultingSingle
will signal aNoSuchElementException
.Note that the inner
Publisher
returned by the handler function should signal eitheronNext
,onError
oronComplete
in response to the receivedThrowable
to indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signalingonNext
followed byonComplete
immediately may result in the sequence to be completed immediately. Similarly, if this innerPublisher
signalsonError
oronComplete
while 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:
retryWhen
does not operate by default on a particularScheduler
.
- Parameters:
handler
- the function that receives aFlowable
of the error theSingle
emits and should return aPublisher
that should signal a normal value (in response to the throwable theFlowable
emits) to trigger a resubscription or signal an error to be the output of the resultingSingle
- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifhandler
isnull
-
safeSubscribe
@SchedulerSupport("none") public final void safeSubscribe(@NonNull @NonNull SingleObserver<? super @NonNull T> observer)
Wraps the givenSingleObserver
, catches anyRuntimeException
s 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
Single
protocol forbids theonXXX
methods to throw, but someSingleObserver
implementation 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:
safeSubscribe
does not operate by default on a particularScheduler
.
- Parameters:
observer
- the potentially misbehavingSingleObserver
- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- Since:
- 3.0.0
- See Also:
subscribe(Consumer,Consumer)
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull CompletableSource other)
Returns aFlowable
which first runs the otherCompletableSource
then the currentSingle
if the other completed normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherCompletableSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull SingleSource<@NonNull T> other)
Returns aFlowable
which first runs the otherSingleSource
then the currentSingle
if the other succeeded normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherSingleSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") @BackpressureSupport(FULL) public final @NonNull Flowable<T> startWith(@NonNull @NonNull MaybeSource<@NonNull T> other)
Returns aFlowable
which first runs the otherMaybeSource
then the currentSingle
if the other succeeded or completed normally.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherMaybeSource
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Observable<T> startWith(@NonNull @NonNull ObservableSource<@NonNull T> other)
Returns anObservable
which first delivers the events of the otherObservableSource
then runs the currentSingle
.- Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherObservableSource
to run first- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
startWith
@CheckReturnValue @NonNull @BackpressureSupport(FULL) @SchedulerSupport("none") public final @NonNull Flowable<T> startWith(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull T> other)
Returns aFlowable
which first delivers the events of the otherPublisher
then runs the currentSingle
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer and expects the otherPublisher
to honor it as well. - Scheduler:
startWith
does not operate by default on a particularScheduler
.
- Parameters:
other
- the otherPublisher
to run first- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifother
isnull
- Since:
- 3.0.0
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe()
Subscribes to aSingle
but ignore its emission or notification.If the
Single
emits an error, it is wrapped into anOnErrorNotImplementedException
and routed to theRxJavaPlugins.onError(Throwable)
handler.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Returns:
- the new
Disposable
instance that can be used for disposing the subscription at any time - See Also:
- ReactiveX operators documentation: Subscribe,
subscribe(Consumer, Consumer, DisposableContainer)
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull BiConsumer<? super @NonNull T,? super java.lang.Throwable> onCallback)
Subscribes to aSingle
and provides a composite callback to handle the item it emits or any error notification it issues.- Scheduler:
subscribe
does 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
Disposable
instance that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonCallback
isnull
- See Also:
subscribe(Consumer, Consumer, DisposableContainer)
, ReactiveX operators documentation: Subscribe
-
subscribe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess)
Subscribes to aSingle
and provides a callback to handle the item it emits.If the
Single
emits an error, it is wrapped into anOnErrorNotImplementedException
and routed to theRxJavaPlugins.onError(Throwable)
handler.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- theConsumer<T>
you have designed to accept the emission from theSingle
- Returns:
- the new
Disposable
instance that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonSuccess
isnull
- See Also:
- ReactiveX operators documentation: Subscribe,
subscribe(Consumer, Consumer, DisposableContainer)
-
subscribe
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError)
Subscribes to aSingle
and provides callbacks to handle the item it emits or any error notification it issues.- Scheduler:
subscribe
does not operate by default on a particularScheduler
.
- Parameters:
onSuccess
- theConsumer<T>
you have designed to accept the emission from theSingle
onError
- theConsumer<Throwable>
you have designed to accept any error notification from theSingle
- Returns:
- the new
Disposable
instance that can be used for disposing the subscription at any time - Throws:
java.lang.NullPointerException
- ifonSuccess
oronError
isnull
- See Also:
- ReactiveX operators documentation: Subscribe,
subscribe(Consumer, Consumer, DisposableContainer)
-
subscribe
@SchedulerSupport("none") @NonNull public final @NonNull Disposable subscribe(@NonNull @NonNull Consumer<? super @NonNull T> onSuccess, @NonNull @NonNull Consumer<? super java.lang.Throwable> onError, @NonNull @NonNull DisposableContainer container)
Wraps the given onXXX callbacks into aDisposable
SingleObserver
, adds it to the givenDisposableContainer
and ensures, that if the upstream terminates or this particularDisposable
is disposed, theSingleObserver
is removed from the given container.The
SingleObserver
will be removed after the callback for the terminal event has been invoked.- Scheduler:
subscribe
does 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 createdDisposable
SingleObserver
- Returns:
- the
Disposable
that allows disposing the particular subscription. - Throws:
java.lang.NullPointerException
- ifonSuccess
,onError
orcontainer
isnull
- Since:
- 3.1.0
-
subscribe
@SchedulerSupport("none") public final void subscribe(@NonNull @NonNull SingleObserver<? super @NonNull T> observer)
Description copied from interface:SingleSource
Subscribes the givenSingleObserver
to thisSingleSource
instance.- Specified by:
subscribe
in 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 incomingSingleObserver
s.There is no need to call any of the plugin hooks on the current
Single
instance or theSingleObserver
; all hooks and basic safeguards have been applied bysubscribe(SingleObserver)
before this method gets called.- Parameters:
observer
- theSingleObserver
to 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 thisSingle
and returns the givenSingleObserver
as is.Usage example:
Single<Integer> source = Single.just(1); CompositeDisposable composite = new CompositeDisposable(); DisposableSingleObserver<Integer> ds = new DisposableSingleObserver<>() { // ... }; composite.add(source.subscribeWith(ds));
- Scheduler:
subscribeWith
does not operate by default on a particularScheduler
.
- Type Parameters:
E
- the type of theSingleObserver
to use and return- Parameters:
observer
- theSingleObserver
(subclass) to use and return, notnull
- Returns:
- the input
observer
- Throws:
java.lang.NullPointerException
- ifobserver
isnull
- Since:
- 2.0
-
subscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> subscribeOn(@NonNull @NonNull Scheduler scheduler)
Asynchronously subscribesSingleObserver
s to thisSingle
on the specifiedScheduler
.- Scheduler:
- You specify which
Scheduler
this operator will use.
- Parameters:
scheduler
- theScheduler
to perform subscription actions on- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- See Also:
- ReactiveX operators documentation: SubscribeOn,
RxJava Threading Examples,
observeOn(io.reactivex.rxjava3.core.Scheduler)
-
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 currentSingle
and signals it as a tuple (Timed
) success value.If the current
Single
fails, the resultingSingle
will pass along the signal to the downstream. To measure the time to error, usematerialize()
and applytimeInterval()
.- Scheduler:
timeInterval
uses thecomputation
Scheduler
for determining the current time upon subscription and upon receiving the success item from the currentSingle
.
- Returns:
- the new
Single
instance - 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 currentSingle
and signals it as a tuple (Timed
) success value.If the current
Single
fails, the resultingSingle
will pass along the signal to the downstream. To measure the time to error, usematerialize()
and applytimeInterval(Scheduler)
.- Scheduler:
timeInterval
uses the providedScheduler
for determining the current time upon subscription and upon receiving the success item from the currentSingle
.
- Parameters:
scheduler
- theScheduler
used for providing the current time- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<Timed<T>> timeInterval(@NonNull @NonNull java.util.concurrent.TimeUnit unit)
Measures the time between the subscription and success item emission of the currentSingle
and signals it as a tuple (Timed
) success value.If the current
Single
fails, the resultingSingle
will pass along the signals to the downstream. To measure the time to error, usematerialize()
and applytimeInterval(TimeUnit, Scheduler)
.- Scheduler:
timeInterval
uses thecomputation
Scheduler
for 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
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 3.0.0
-
timeInterval
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<Timed<T>> timeInterval(@NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Measures the time between the subscription and success item emission of the currentSingle
and signals it as a tuple (Timed
) success value.If the current
Single
is empty or fails, the resultingSingle
will pass along the signals to the downstream. To measure the time to termination, usematerialize()
and applytimeInterval(TimeUnit, Scheduler)
.- Scheduler:
timeInterval
uses the providedScheduler
for determining the current time upon subscription and upon receiving the success item from the currentSingle
.
- Parameters:
unit
- the time unit for measurementscheduler
- theScheduler
used for providing the current time- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<Timed<T>> timestamp()
Combines the success value from the currentSingle
with the current time (in milliseconds) of its reception, using thecomputation
Scheduler
as time source, then signals them as aTimed
instance.If the current
Single
is empty or fails, the resultingSingle
will pass along the signals to the downstream. To get the timestamp of the error, usematerialize()
and applytimestamp()
.- Scheduler:
timestamp
uses thecomputation
Scheduler
for determining the current time upon receiving the success item from the currentSingle
.
- Returns:
- the new
Single
instance - 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 currentSingle
with the current time (in milliseconds) of its reception, using the givenScheduler
as time source, then signals them as aTimed
instance.If the current
Single
is empty or fails, the resultingSingle
will pass along the signals to the downstream. To get the timestamp of the error, usematerialize()
and applytimestamp(Scheduler)
.- Scheduler:
timestamp
uses the providedScheduler
for determining the current time upon receiving the success item from the currentSingle
.
- Parameters:
scheduler
- theScheduler
used for providing the current time- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<Timed<T>> timestamp(@NonNull @NonNull java.util.concurrent.TimeUnit unit)
Combines the success value from the currentSingle
with the current time of its reception, using thecomputation
Scheduler
as time source, then signals it as aTimed
instance.If the current
Single
is empty or fails, the resultingSingle
will pass along the signals to the downstream. To get the timestamp of the error, usematerialize()
and applytimestamp(TimeUnit)
.- Scheduler:
timestamp
uses thecomputation
Scheduler
, for determining the current time upon receiving the success item from the currentSingle
.
- Parameters:
unit
- the time unit for measurement- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 3.0.0
-
timestamp
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<Timed<T>> timestamp(@NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Combines the success value from the currentSingle
with the current time of its reception, using the givenScheduler
as time source, then signals it as aTimed
instance.If the current
Single
is empty or fails, the resultingSingle
will pass along the signals to the downstream. To get the timestamp of the error, usematerialize()
and applytimestamp(TimeUnit, Scheduler)
.- Scheduler:
timestamp
uses 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
- theScheduler
used for providing the current time- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- Since:
- 3.0.0
-
takeUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final @NonNull Single<T> takeUntil(@NonNull @NonNull CompletableSource other)
Returns aSingle
that emits the item emitted by the currentSingle
until aCompletableSource
terminates. Upon termination ofother
, this will emit aCancellationException
rather than go toSingleObserver.onSuccess(Object)
.- Scheduler:
takeUntil
does not operate by default on a particularScheduler
.
- Parameters:
other
- theCompletableSource
whose termination will causetakeUntil
to emit the item from the currentSingle
- Returns:
- the new
Single
that emits the item emitted by the currentSingle
until such time asother
terminates. - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: TakeUntil
-
takeUntil
@BackpressureSupport(FULL) @CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull E> @NonNull Single<T> takeUntil(@NonNull @NonNull org.reactivestreams.Publisher<@NonNull E> other)
Returns aSingle
that emits the item emitted by the currentSingle
until aPublisher
emits an item or completes. Upon emission of an item fromother
, this will emit aCancellationException
rather than go toSingleObserver.onSuccess(Object)
.- Backpressure:
- The
other
publisher is consumed in an unbounded fashion but will be cancelled after the first item it produced. - Scheduler:
takeUntil
does not operate by default on a particularScheduler
.
- Type Parameters:
E
- the type of items emitted byother
- Parameters:
other
- thePublisher
whose first emitted item or completion will causetakeUntil
to emitCancellationException
if the currentSingle
hasn't completed till then- Returns:
- the new
Single
that emits the item emitted by the currentSingle
until such time asother
emits its first item - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: TakeUntil
-
takeUntil
@CheckReturnValue @NonNull @SchedulerSupport("none") public final <@NonNull E> @NonNull Single<T> takeUntil(@NonNull @NonNull SingleSource<? extends @NonNull E> other)
Returns aSingle
that emits the item emitted by the currentSingle
until a secondSingle
emits an item. Upon emission of an item fromother
, this will emit aCancellationException
rather than go toSingleObserver.onSuccess(Object)
.- Scheduler:
takeUntil
does not operate by default on a particularScheduler
.
- Type Parameters:
E
- the type of item emitted byother
- Parameters:
other
- theSingle
whose emitted item will causetakeUntil
to emitCancellationException
if the currentSingle
hasn't completed till then- Returns:
- the new
Single
that emits the item emitted by the currentSingle
until such time asother
emits its item - Throws:
java.lang.NullPointerException
- ifother
isnull
- See Also:
- ReactiveX operators documentation: TakeUntil
-
timeout
@CheckReturnValue @SchedulerSupport("io.reactivex:computation") @NonNull public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit)
Signals aTimeoutException
if the currentSingle
doesn't signal a success value within the specified timeout window.- Scheduler:
timeout
signals theTimeoutException
on thecomputation
Scheduler
.
- Parameters:
timeout
- the timeout amountunit
- the time unit- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
isnull
- Since:
- 2.0
-
timeout
@CheckReturnValue @SchedulerSupport("custom") @NonNull public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler)
Signals aTimeoutException
if the currentSingle
doesn't signal a success value within the specified timeout window.- Scheduler:
timeout
signals theTimeoutException
on theScheduler
you specify.
- Parameters:
timeout
- the timeout amountunit
- the time unitscheduler
- the targetScheduler
where the timeout is awaited and theTimeoutException
signaled- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
orscheduler
isnull
- Since:
- 2.0
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull Scheduler scheduler, @NonNull @NonNull SingleSource<? extends @NonNull T> fallback)
Runs the currentSingle
and if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSource
subscribed to.- Scheduler:
timeout
subscribes to the otherSingleSource
on theScheduler
you specify.
- Parameters:
timeout
- the timeout amountunit
- the time unitscheduler
- theScheduler
where the timeout is awaited and the subscription to other happensfallback
- the otherSingleSource
that gets subscribed to if the currentSingle
times out- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifunit
,scheduler
orfallback
isnull
- Since:
- 2.0
-
timeout
@CheckReturnValue @NonNull @SchedulerSupport("io.reactivex:computation") public final @NonNull Single<T> timeout(long timeout, @NonNull @NonNull java.util.concurrent.TimeUnit unit, @NonNull @NonNull SingleSource<? extends @NonNull T> fallback)
Runs the currentSingle
and if it doesn't signal within the specified timeout window, it is disposed and the otherSingleSource
subscribed to.- Scheduler:
timeout
subscribes to the otherSingleSource
on thecomputation
Scheduler
.
- Parameters:
timeout
- the timeout amountunit
- the time unitfallback
- the otherSingleSource
that gets subscribed to if the currentSingle
times out- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- iffallback
orunit
isnull
- Since:
- 2.0
-
timeout0
private Single<T> timeout0(long timeout, java.util.concurrent.TimeUnit unit, Scheduler scheduler, SingleSource<? extends @NonNull T> fallback)
-
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:
to
does 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 currentSingle
instance and returns a value- Returns:
- the converted value
- Throws:
java.lang.NullPointerException
- ifconverter
isnull
- Since:
- 2.2
-
ignoreElement
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Completable ignoreElement()
Returns aCompletable
that ignores the success value of thisSingle
and signalsonComplete
instead.- Scheduler:
ignoreElement
does not operate by default on a particularScheduler
.
- Returns:
- the new
Completable
instance - Since:
- 2.1.13
-
toFlowable
@BackpressureSupport(FULL) @CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Flowable<T> toFlowable()
Converts thisSingle
into aFlowable
.- Backpressure:
- The returned
Flowable
honors the backpressure of the downstream consumer. - Scheduler:
toFlowable
does not operate by default on a particularScheduler
.
- Returns:
- the new
Flowable
instance
-
toFuture
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull java.util.concurrent.Future<T> toFuture()
Returns aFuture
representing the single value emitted by thisSingle
.Cancelling the
Future
will cancel the subscription to the currentSingle
.- Scheduler:
toFuture
does not operate by default on a particularScheduler
.
- Returns:
- the new
Future
instance - See Also:
- ReactiveX documentation: To
-
toMaybe
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Maybe<T> toMaybe()
Converts thisSingle
into aMaybe
.- Scheduler:
toMaybe
does not operate by default on a particularScheduler
.
- Returns:
- the new
Maybe
instance
-
toObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull Observable<T> toObservable()
Converts thisSingle
into anObservable
.- Scheduler:
toObservable
does not operate by default on a particularScheduler
.
- Returns:
- the new
Observable
instance
-
unsubscribeOn
@CheckReturnValue @NonNull @SchedulerSupport("custom") public final @NonNull Single<T> unsubscribeOn(@NonNull @NonNull Scheduler scheduler)
Returns aSingle
which makes sure when aSingleObserver
disposes theDisposable
, that call is propagated up on the specifiedScheduler
.- Scheduler:
unsubscribeOn
callsdispose()
of the upstream on theScheduler
you specify.
History: 2.0.9 - experimental
- Parameters:
scheduler
- the target scheduler where to execute the disposal- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifscheduler
isnull
- 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 aSingle
that emits the result of applying a specified function to the pair of items emitted by the currentSingle
and another specifiedSingleSource
.- Scheduler:
zipWith
does not operate by default on a particularScheduler
.
- Type Parameters:
U
- the type of items emitted by theother
Single
R
- the type of items emitted by the resultingSingle
- Parameters:
other
- the otherSingleSource
zipper
- a function that combines the pairs of items from the twoSingleSource
s to generate the items to be emitted by the resultingSingle
- Returns:
- the new
Single
that pairs up values from the currentSingle
and theother
SingleSource
and emits the results ofzipFunction
applied to these pairs - Throws:
java.lang.NullPointerException
- ifother
orzipper
isnull
- See Also:
- ReactiveX operators documentation: Zip
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<T> test()
Creates aTestObserver
and subscribes it to thisSingle
.- Scheduler:
test
does not operate by default on a particularScheduler
.
- Returns:
- the new
TestObserver
instance - Since:
- 2.0
-
test
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull TestObserver<T> test(boolean dispose)
Creates aTestObserver
optionally in cancelled state, then subscribes it to thisSingle
.- Scheduler:
test
does not operate by default on a particularScheduler
.
- Parameters:
dispose
- iftrue
, theTestObserver
will be cancelled before subscribing to thisSingle
.- Returns:
- the new
TestObserver
instance - Since:
- 2.0
-
toSingle
@NonNull private static <T> @NonNull Single<T> toSingle(@NonNull @NonNull Flowable<T> source)
-
fromCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public static <@NonNull T> @NonNull Single<@NonNull T> fromCompletionStage(@NonNull @NonNull java.util.concurrent.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 theCompletionStage
is to be created per consumer upon subscription, usedefer(Supplier)
aroundfromCompletionStage
:Single.defer(() -> Single.fromCompletionStage(createCompletionStage()));
If the
CompletionStage
completes withnull
, the resultingSingle
is terminated with aNullPointerException
.Canceling the flow can't cancel the execution of the
CompletionStage
becauseCompletionStage
itself doesn't support cancellation. Instead, the operator detaches from theCompletionStage
.- Scheduler:
fromCompletionStage
does not operate by default on a particularScheduler
.
- Type Parameters:
T
- the element type of theCompletionStage
- Parameters:
stage
- theCompletionStage
to convert toSingle
and signal its success value or error- Returns:
- the new
Single
instance - Throws:
java.lang.NullPointerException
- ifstage
isnull
- Since:
- 3.0.0
-
mapOptional
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Maybe<R> mapOptional(@NonNull @NonNull Function<? super @NonNull T,@NonNull java.util.Optional<? extends @NonNull R>> mapper)
Maps the upstream success value into anOptional
and emits the contained item if not empty as aMaybe
.- Scheduler:
mapOptional
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the non-null
output type- Parameters:
mapper
- the function that receives the upstream success item and should return a non-emptyOptional
to emit as the success output or an emptyOptional
to complete theMaybe
- Returns:
- the new
Maybe
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
map(Function)
,filter(Predicate)
-
toCompletionStage
@CheckReturnValue @SchedulerSupport("none") @NonNull public final @NonNull java.util.concurrent.CompletionStage<T> toCompletionStage()
Signals the upstream success item (or error) via aCompletionStage
.The upstream can be canceled by converting the resulting
CompletionStage
intoCompletableFuture
viaCompletionStage.toCompletableFuture()
and callingCompletableFuture.cancel(boolean)
on it. The upstream will be also cancelled if the resultingCompletionStage
is converted to and completed manually byCompletableFuture.complete(Object)
orCompletableFuture.completeExceptionally(Throwable)
.- Scheduler:
toCompletionStage
does not operate by default on a particularScheduler
.
- Returns:
- the new
CompletionStage
instance - 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,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as aFlowable
.The operator closes the
Stream
upon cancellation and when it terminates. The exceptions raised when closing aStream
are routed to the global error handler (RxJavaPlugins.onError(Throwable)
. If aStream
should not be closed, turn it into anIterable
and 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());
Stream
does 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
Stream
on demand (i.e., when requested). - Scheduler:
flattenStreamAsFlowable
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the element type of theStream
and the outputFlowable
- Parameters:
mapper
- the function that receives the upstream success item and should return aStream
of values to emit.- Returns:
- the new
Flowable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
flattenAsFlowable(Function)
,flattenStreamAsObservable(Function)
-
flattenStreamAsObservable
@CheckReturnValue @SchedulerSupport("none") @NonNull public final <@NonNull R> @NonNull Observable<R> flattenStreamAsObservable(@NonNull @NonNull Function<? super @NonNull T,? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
Maps the upstream succecss value into a JavaStream
and emits its items to the downstream consumer as anObservable
.The operator closes the
Stream
upon cancellation and when it terminates. The exceptions raised when closing aStream
are routed to the global error handler (RxJavaPlugins.onError(Throwable)
. If aStream
should not be closed, turn it into anIterable
and 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());
Stream
does not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.- Scheduler:
flattenStreamAsObservable
does not operate by default on a particularScheduler
.
- Type Parameters:
R
- the element type of theStream
and the outputObservable
- Parameters:
mapper
- the function that receives the upstream success item and should return aStream
of values to emit.- Returns:
- the new
Observable
instance - Throws:
java.lang.NullPointerException
- ifmapper
isnull
- Since:
- 3.0.0
- See Also:
flattenAsObservable(Function)
,flattenStreamAsFlowable(Function)
-
-