T
- the type of the item emitted by the Single
public abstract class Single<T> extends Object implements SingleSource<T>
Single
class implements the Reactive Pattern for a single value response.
Single
behaves similarly to Observable
except that it can only emit either a single successful
value or an error (there is no onComplete
notification as there is for an Observable
).
The Single
class implements the SingleSource
base interface and the default consumer
type it interacts with is the SingleObserver
via the subscribe(SingleObserver)
method.
The Single
operates with the following sequential protocol:
onSubscribe (onSuccess | onError)?
Note that onSuccess
and onError
are mutually exclusive events; unlike Observable
,
onSuccess
is never followed by onError
.
Like Observable
, a running Single
can be stopped through the Disposable
instance
provided to consumers through SingleObserver.onSubscribe(io.reactivex.rxjava3.disposables.Disposable)
.
Like an Observable
, a Single
is lazy, can be either "hot" or "cold", synchronous or
asynchronous. Single
instances returned by the methods of this class are cold
and there is a standard hot implementation in the form of a subject:
SingleSubject
.
The documentation for this class makes use of marble diagrams. The following legend explains these diagrams:
See Flowable
or Observable
for the
implementation of the Reactive Pattern for a stream or vector of values.
For more information see the ReactiveX documentation.
Example:
Disposable d = Single.just("Hello World")
.delay(10, TimeUnit.SECONDS, Schedulers.io())
.subscribeWith(new DisposableSingleObserver<String>() {
@Override
public void onStart() {
System.out.println("Started");
}
@Override
public void onSuccess(String value) {
System.out.println("Success: " + value);
}
@Override
public void onError(Throwable error) {
error.printStackTrace();
}
});
Thread.sleep(5000);
d.dispose();
Note that by design, subscriptions via subscribe(SingleObserver)
can't be disposed
from the outside (hence the
void
return of the subscribe(SingleObserver)
method) and it is the
responsibility of the implementor of the SingleObserver
to allow this to happen.
RxJava supports such usage with the standard
DisposableSingleObserver
instance.
For convenience, the subscribeWith(SingleObserver)
method is provided as well to
allow working with a SingleObserver
(or subclass) instance to be applied with in
a fluent manner (such as in the example above).
DisposableSingleObserver
Constructor and Description |
---|
Single() |
Modifier and Type | Method and Description |
---|---|
static <T> @NonNull Single<T> |
amb(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Runs multiple
SingleSource s and signals the events of the first one that signals (disposing
the rest). |
static <T> @NonNull Single<T> |
ambArray(SingleSource<? extends T>... sources)
Runs multiple
SingleSource s and signals the events of the first one that signals (disposing
the rest). |
@NonNull Single<T> |
ambWith(@NonNull SingleSource<? extends T> other)
Signals the event of this or the other
SingleSource whichever signals first. |
T |
blockingGet()
Waits in a blocking fashion until the current
Single signals a success value (which is returned) or
an exception (which is propagated). |
void |
blockingSubscribe()
Subscribes to the current
Single and blocks the current thread until it terminates. |
void |
blockingSubscribe(@NonNull Consumer<? super T> onSuccess)
Subscribes to the current
Single and calls given onSuccess callback on the current thread
when it completes normally. |
void |
blockingSubscribe(@NonNull Consumer<? super T> onSuccess,
@NonNull Consumer<? super Throwable> onError)
Subscribes to the current
Single and calls the appropriate callback on the current thread
when it terminates. |
void |
blockingSubscribe(@NonNull SingleObserver<? super T> observer)
Subscribes to the current
Single and calls the appropriate SingleObserver method on the current thread. |
@NonNull Single<T> |
cache()
Stores the success value or exception from the current
Single and replays it to late SingleObserver s. |
<U> @NonNull Single<U> |
cast(@NonNull Class<? extends U> clazz)
Casts the success value of the current
Single into the target type or signals a
ClassCastException if not compatible. |
<R> @NonNull Single<R> |
compose(@NonNull SingleTransformer<? super T,? extends R> transformer)
Transform a
Single by applying a particular SingleTransformer function to it. |
static <T> @NonNull Flowable<T> |
concat(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Concatenate the single values, in a non-overlapping fashion, of the
SingleSource s provided by
an Iterable sequence. |
static <T> @NonNull Observable<T> |
concat(@NonNull ObservableSource<? extends SingleSource<? extends T>> sources)
Concatenate the single values, in a non-overlapping fashion, of the
SingleSource s provided by
an ObservableSource sequence. |
static <T> @NonNull Flowable<T> |
concat(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Concatenate the single values, in a non-overlapping fashion, of the
SingleSource s provided by
a Publisher sequence. |
static <T> @NonNull Flowable<T> |
concat(@NonNull Publisher<? extends SingleSource<? extends T>> sources,
int prefetch)
Concatenate the single values, in a non-overlapping fashion, of the
SingleSource s provided by
a Publisher sequence and prefetched by the specified amount. |
static <T> @NonNull Flowable<T> |
concat(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2)
Returns a
Flowable that emits the items emitted by two SingleSource s, one after the other. |
static <T> @NonNull Flowable<T> |
concat(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2,
@NonNull SingleSource<? extends T> source3)
Returns a
Flowable that emits the items emitted by three SingleSource s, one after the other. |
static <T> @NonNull Flowable<T> |
concat(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2,
@NonNull SingleSource<? extends T> source3,
@NonNull SingleSource<? extends T> source4)
Returns a
Flowable that emits the items emitted by four SingleSource s, one after the other. |
static <T> @NonNull Flowable<T> |
concatArray(SingleSource<? extends T>... sources)
Concatenate the single values, in a non-overlapping fashion, of the
SingleSource s provided in
an array. |
static <T> @NonNull Flowable<T> |
concatArrayDelayError(SingleSource<? extends T>... sources)
Concatenate the single values, in a non-overlapping fashion, of the
SingleSource s provided in
an array. |
static <T> @NonNull Flowable<T> |
concatArrayEager(SingleSource<? extends T>... sources)
Concatenates a sequence of
SingleSource eagerly into a single stream of values. |
static <T> @NonNull Flowable<T> |
concatArrayEagerDelayError(SingleSource<? extends T>... sources)
Concatenates a sequence of
SingleSource eagerly into a single stream of values. |
static <T> @NonNull Flowable<T> |
concatDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Concatenates the
Iterable sequence of SingleSource s into a single sequence by subscribing to each SingleSource ,
one after the other, one at a time and delays any errors till the all inner SingleSource s terminate
as a Flowable sequence. |
static <T> @NonNull Flowable<T> |
concatDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Concatenates the
Publisher sequence of SingleSource s into a single sequence by subscribing to each inner SingleSource ,
one after the other, one at a time and delays any errors till the all inner and the outer Publisher terminate
as a Flowable sequence. |
static <T> @NonNull Flowable<T> |
concatDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources,
int prefetch)
Concatenates the
Publisher sequence of SingleSource s into a single sequence by subscribing to each inner SingleSource ,
one after the other, one at a time and delays any errors till the all inner and the outer Publisher terminate
as a Flowable sequence. |
static <T> @NonNull Flowable<T> |
concatEager(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Concatenates an
Iterable sequence of SingleSource s eagerly into a single stream of values. |
static <T> @NonNull Flowable<T> |
concatEager(@NonNull Iterable<? extends SingleSource<? extends T>> sources,
int maxConcurrency)
Concatenates an
Iterable sequence of SingleSource s eagerly into a single stream of values and
runs a limited number of the inner sources at once. |
static <T> @NonNull Flowable<T> |
concatEager(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Concatenates a
Publisher sequence of SingleSource s eagerly into a single stream of values. |
static <T> @NonNull Flowable<T> |
concatEager(@NonNull Publisher<? extends SingleSource<? extends T>> sources,
int maxConcurrency)
Concatenates a
Publisher sequence of SingleSource s eagerly into a single stream of values and
runs a limited number of those inner SingleSource s at once. |
static <T> @NonNull Flowable<T> |
concatEagerDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Concatenates an
Iterable sequence of SingleSource s eagerly into a single stream of values,
delaying errors until all the inner sources terminate. |
static <T> @NonNull Flowable<T> |
concatEagerDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources,
int maxConcurrency)
Concatenates an
Iterable sequence of SingleSource s eagerly into a single stream of values,
delaying errors until all the inner sources terminate. |
static <T> @NonNull Flowable<T> |
concatEagerDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Concatenates a
Publisher sequence of SingleSource s eagerly into a single stream of values,
delaying errors until all the inner and the outer sequence terminate. |
static <T> @NonNull Flowable<T> |
concatEagerDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources,
int maxConcurrency)
Concatenates a
Publisher sequence of SingleSource s eagerly into a single stream of values,
running at most the specified number of those inner SingleSource s at once and
delaying errors until all the inner and the outer sequence terminate. |
<R> @NonNull Single<R> |
concatMap(@NonNull Function<? super T,? extends SingleSource<? extends R>> mapper)
Returns a
Single that is based on applying a specified function to the item emitted by the current Single ,
where that function returns a SingleSource . |
@NonNull Completable |
concatMapCompletable(@NonNull Function<? super T,? extends CompletableSource> mapper)
Returns a
Completable that completes based on applying a specified function to the item emitted by the
current Single , where that function returns a CompletableSource . |
<R> @NonNull Maybe<R> |
concatMapMaybe(@NonNull Function<? super T,? extends MaybeSource<? extends R>> mapper)
Returns a
Maybe that is based on applying a specified function to the item emitted by the current Single ,
where that function returns a MaybeSource . |
@NonNull Flowable<T> |
concatWith(@NonNull SingleSource<? extends T> other)
Returns a
Flowable that emits the item emitted by the current Single , then the item emitted by the
specified SingleSource . |
@NonNull Single<Boolean> |
contains(@NonNull Object item)
Signals
true if the current Single signals a success value that is Object.equals(Object) with the value
provided. |
@NonNull Single<Boolean> |
contains(@NonNull Object item,
@NonNull BiPredicate<Object,Object> comparer)
Signals
true if the current Single signals a success value that is equal with
the value provided by calling a BiPredicate . |
static <T> @NonNull Single<T> |
create(@NonNull SingleOnSubscribe<T> source)
Provides an API (via a cold
Single ) that bridges the reactive world with the callback-style world. |
static <T> @NonNull Single<T> |
defer(@NonNull Supplier<? extends SingleSource<? extends T>> supplier)
Calls a
Supplier for each individual SingleObserver to return the actual SingleSource to
be subscribed to. |
@NonNull Single<T> |
delay(long time,
@NonNull TimeUnit unit)
Delays the emission of the success signal from the current
Single by the specified amount. |
@NonNull Single<T> |
delay(long time,
@NonNull TimeUnit unit,
boolean delayError)
Delays the emission of the success or error signal from the current
Single by the specified amount. |
@NonNull Single<T> |
delay(long time,
@NonNull TimeUnit unit,
@NonNull Scheduler scheduler)
Delays the emission of the success signal from the current
Single by the specified amount. |
@NonNull Single<T> |
delay(long time,
@NonNull TimeUnit unit,
@NonNull Scheduler scheduler,
boolean delayError)
Delays the emission of the success or error signal from the current
Single by the specified amount. |
@NonNull Single<T> |
delaySubscription(@NonNull CompletableSource subscriptionIndicator)
Delays the actual subscription to the current
Single until the given other CompletableSource
completes. |
@NonNull Single<T> |
delaySubscription(long time,
@NonNull TimeUnit unit)
Delays the actual subscription to the current
Single until the given time delay elapsed. |
@NonNull Single<T> |
delaySubscription(long time,
@NonNull TimeUnit unit,
@NonNull Scheduler scheduler)
Delays the actual subscription to the current
Single until the given time delay elapsed. |
<U> @NonNull Single<T> |
delaySubscription(@NonNull ObservableSource<U> subscriptionIndicator)
Delays the actual subscription to the current
Single until the given other ObservableSource
signals its first value or completes. |
<U> @NonNull Single<T> |
delaySubscription(@NonNull Publisher<U> subscriptionIndicator)
Delays the actual subscription to the current
Single until the given other Publisher
signals its first value or completes. |
<U> @NonNull Single<T> |
delaySubscription(@NonNull SingleSource<U> subscriptionIndicator)
Delays the actual subscription to the current
Single until the given other SingleSource
signals success. |
<R> @NonNull Maybe<R> |
dematerialize(@NonNull Function<? super T,Notification<R>> selector)
Maps the
Notification success value of the current Single back into normal
onSuccess , onError or onComplete signals as a
Maybe source. |
@NonNull Single<T> |
doAfterSuccess(@NonNull Consumer<? super 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 this
Single signals onSuccess or onError or gets disposed by
the downstream. |
@NonNull Single<T> |
doOnDispose(@NonNull Action onDispose)
Calls the shared
Action if a SingleObserver subscribed to the current Single
disposes the common Disposable it received via onSubscribe . |
@NonNull Single<T> |
doOnError(@NonNull Consumer<? super Throwable> onError)
Calls the shared consumer with the error sent via
onError for each
SingleObserver that subscribes to the current Single . |
@NonNull Single<T> |
doOnEvent(@NonNull BiConsumer<? super T,? super Throwable> onEvent)
Calls the shared consumer with the error sent via
onError or the value
via onSuccess for each SingleObserver that subscribes to the current Single . |
@NonNull Single<T> |
doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe,
@NonNull Action onDispose)
Calls the appropriate
onXXX method (shared between all SingleObserver s) for the lifecycle events of
the sequence (subscription, disposal). |
@NonNull Single<T> |
doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe)
Calls the shared consumer with the
Disposable sent through the onSubscribe for each
SingleObserver that subscribes to the current Single . |
@NonNull Single<T> |
doOnSuccess(@NonNull Consumer<? super T> onSuccess)
Calls the shared consumer with the success value sent via
onSuccess for each
SingleObserver that subscribes to the current Single . |
@NonNull Single<T> |
doOnTerminate(@NonNull Action onTerminate)
Returns a
Single instance that calls the given onTerminate callback
just before this Single completes normally or with an exception. |
static <T> @NonNull Single<T> |
error(@NonNull Supplier<? extends Throwable> supplier)
Signals a
Throwable returned by the callback function for each individual SingleObserver . |
static <T> @NonNull Single<T> |
error(@NonNull Throwable throwable)
Returns a
Single that invokes a subscriber's onError method when the
subscriber subscribes to it. |
@NonNull Maybe<T> |
filter(@NonNull Predicate<? super T> predicate)
Filters the success item of the
Single via a predicate function and emitting it if the predicate
returns true , completing otherwise. |
<R> @NonNull Single<R> |
flatMap(@NonNull Function<? super T,? extends SingleSource<? extends R>> mapper)
Returns a
Single that is based on applying a specified function to the item emitted by the current Single ,
where that function returns a SingleSource . |
<R> @NonNull Single<R> |
flatMap(@NonNull Function<? super T,? extends SingleSource<? extends R>> onSuccessMapper,
@NonNull Function<? super Throwable,? extends SingleSource<? extends R>> onErrorMapper)
Maps the
onSuccess or onError signals of the current Single into a SingleSource and emits that
SingleSource 's signals. |
<U,R> @NonNull Single<R> |
flatMap(@NonNull Function<? super T,? extends SingleSource<? extends U>> mapper,
@NonNull BiFunction<? super T,? super U,? extends R> combiner)
Returns a
Single that emits the results of a specified function to the pair of values emitted by the
current Single and a specified mapped SingleSource . |
@NonNull Completable |
flatMapCompletable(@NonNull Function<? super T,? extends CompletableSource> mapper)
Returns a
Completable that completes based on applying a specified function to the item emitted by the
current Single , where that function returns a CompletableSource . |
<R> @NonNull Maybe<R> |
flatMapMaybe(@NonNull Function<? super T,? extends MaybeSource<? extends R>> mapper)
Returns a
Maybe that is based on applying a specified function to the item emitted by the current Single ,
where that function returns a MaybeSource . |
<R> @NonNull Observable<R> |
flatMapObservable(@NonNull Function<? super T,? extends ObservableSource<? extends R>> mapper)
Returns an
Observable that is based on applying a specified function to the item emitted by the current Single ,
where that function returns an ObservableSource . |
<R> @NonNull Flowable<R> |
flatMapPublisher(@NonNull Function<? super T,? extends Publisher<? extends R>> mapper)
|
<U> @NonNull Flowable<U> |
flattenAsFlowable(@NonNull Function<? super T,? extends Iterable<? extends U>> mapper)
|
<U> @NonNull Observable<U> |
flattenAsObservable(@NonNull Function<? super T,? extends Iterable<? extends U>> mapper)
Maps the success value of the current
Single into an Iterable and emits its items as an
Observable sequence. |
<R> @NonNull Flowable<R> |
flattenStreamAsFlowable(@NonNull Function<? super T,? extends Stream<? extends R>> mapper)
|
<R> @NonNull Observable<R> |
flattenStreamAsObservable(@NonNull Function<? super T,? extends Stream<? extends R>> mapper)
Maps the upstream succecss value into a Java
Stream and emits its
items to the downstream consumer as an Observable . |
static <T> @NonNull Single<T> |
fromCallable(@NonNull Callable<? extends T> callable)
Returns a
Single that invokes the given Callable for each incoming SingleObserver
and emits its value or exception to them. |
static <T> @NonNull Single<T> |
fromCompletionStage(@NonNull CompletionStage<T> stage)
Signals the completion value or error of the given (hot)
CompletionStage -based asynchronous calculation. |
static <T> @NonNull Single<T> |
fromFuture(@NonNull Future<? extends T> future)
Converts a
Future into a Single and awaits its outcome in a blocking fashion. |
static <T> @NonNull Single<T> |
fromFuture(@NonNull Future<? extends T> future,
long timeout,
@NonNull TimeUnit unit)
Converts a
Future into a Single and awaits its outcome, or timeout, in a blocking fashion. |
static <T> @NonNull Single<T> |
fromMaybe(@NonNull MaybeSource<T> maybe)
Returns a
Single instance that when subscribed to, subscribes to the MaybeSource instance and
emits onSuccess as a single item, turns an onComplete into NoSuchElementException error signal or
forwards the onError signal. |
static <T> @NonNull Single<T> |
fromMaybe(@NonNull MaybeSource<T> maybe,
T defaultItem)
Returns a
Single instance that when subscribed to, subscribes to the MaybeSource instance and
emits onSuccess as a single item, emits the defaultItem for an onComplete signal or
forwards the onError signal. |
static <T> @NonNull Single<T> |
fromObservable(@NonNull ObservableSource<? extends T> observable)
Wraps a specific
ObservableSource into a Single and signals its single element or error. |
static <T> @NonNull Single<T> |
fromPublisher(@NonNull Publisher<? extends T> publisher)
Wraps a specific
Publisher into a Single and signals its single element or error. |
static <T> @NonNull Single<T> |
fromSupplier(@NonNull Supplier<? extends T> supplier)
Returns a
Single that invokes passed supplier and emits its result
for each individual SingleObserver that subscribes. |
@NonNull Single<T> |
hide()
Hides the identity of the current
Single , including the Disposable that is sent
to the downstream via onSubscribe() . |
@NonNull Completable |
ignoreElement()
|
static <T> @NonNull Single<T> |
just(T item)
Returns a
Single that emits a specified item. |
<R> @NonNull Single<R> |
lift(@NonNull SingleOperator<? extends R,? super T> lift)
This method requires advanced knowledge about building operators, please consider
other standard composition methods first;
Returns a
Single which, when subscribed to, invokes the apply(SingleObserver) method
of the provided SingleOperator for each individual downstream Single and allows the
insertion of a custom operator by accessing the downstream's SingleObserver during this subscription phase
and providing a new SingleObserver , containing the custom operator's intended business logic, that will be
used in the subscription process going further upstream. |
<R> @NonNull Single<R> |
map(@NonNull Function<? super T,? extends R> mapper)
Returns a
Single that applies a specified function to the item emitted by the current Single and
emits the result of this function application. |
<R> @NonNull Maybe<R> |
mapOptional(@NonNull Function<? super T,Optional<? extends R>> mapper)
|
@NonNull Single<Notification<T>> |
materialize()
Maps the signal types of this
Single into a Notification of the same kind
and emits it as a single success value to downstream. |
static <T> @NonNull Flowable<T> |
merge(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Merges an
Iterable sequence of SingleSource instances into a single Flowable sequence,
running all SingleSource s at once. |
static <T> @NonNull Flowable<T> |
merge(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Merges a sequence of
SingleSource instances emitted by a Publisher into a single Flowable sequence,
running all SingleSource s at once. |
static <T> @NonNull Single<T> |
merge(@NonNull SingleSource<? extends SingleSource<? extends T>> source)
Flattens a
SingleSource that emits a SingleSingle into a single Single that emits the item
emitted by the nested SingleSource , without any transformation. |
static <T> @NonNull Flowable<T> |
merge(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2)
Flattens two
SingleSource s into one Flowable sequence, without any transformation. |
static <T> @NonNull Flowable<T> |
merge(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2,
@NonNull SingleSource<? extends T> source3)
Flattens three
SingleSource s into one Flowable sequence, without any transformation. |
static <T> @NonNull Flowable<T> |
merge(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2,
@NonNull SingleSource<? extends T> source3,
@NonNull SingleSource<? extends T> source4)
Flattens four
SingleSource s into one Flowable sequence, without any transformation. |
static <T> @NonNull Flowable<T> |
mergeArray(SingleSource<? extends T>... sources)
Merges an array of
SingleSource instances into a single Flowable sequence,
running all SingleSource s at once. |
static <T> @NonNull Flowable<T> |
mergeArrayDelayError(SingleSource<? extends T>... sources)
Flattens an array of
SingleSource s into one Flowable , in a way that allows a subscriber to receive all
successfully emitted items from each of the source SingleSource s without being interrupted by an error
notification from one of them. |
static <T> @NonNull Flowable<T> |
mergeDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Merges an
Iterable sequence of SingleSource instances into one Flowable sequence,
running all SingleSource s at once and delaying any error(s) until all sources succeed or fail. |
static <T> @NonNull Flowable<T> |
mergeDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Merges a sequence of
SingleSource instances emitted by a Publisher into a Flowable sequence,
running all SingleSource s at once and delaying any error(s) until all sources succeed or fail. |
static <T> @NonNull Flowable<T> |
mergeDelayError(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2)
Flattens two
SingleSource s into one Flowable , without any transformation, delaying
any error(s) until all sources succeed or fail. |
static <T> @NonNull Flowable<T> |
mergeDelayError(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2,
@NonNull SingleSource<? extends T> source3)
Flattens two
SingleSource s into one Flowable , without any transformation, delaying
any error(s) until all sources succeed or fail. |
static <T> @NonNull Flowable<T> |
mergeDelayError(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2,
@NonNull SingleSource<? extends T> source3,
@NonNull SingleSource<? extends T> source4)
Flattens two
SingleSource s into one Flowable , without any transformation, delaying
any error(s) until all sources succeed or fail. |
@NonNull Flowable<T> |
mergeWith(@NonNull SingleSource<? extends T> other)
|
static <T> @NonNull Single<T> |
never()
Returns a singleton instance of a never-signaling
Single (only calls onSubscribe ). |
@NonNull Single<T> |
observeOn(@NonNull Scheduler scheduler)
Signals the success item or the terminal signals of the current
Single on the specified Scheduler ,
asynchronously. |
<U> @NonNull Maybe<U> |
ofType(@NonNull Class<U> clazz)
Filters the items emitted by the current
Single , only emitting its success value if that
is an instance of the supplied Class . |
@NonNull Maybe<T> |
onErrorComplete()
Returns a
Maybe instance that if the current Single emits an error, it will emit an onComplete
and swallow the throwable. |
@NonNull Maybe<T> |
onErrorComplete(@NonNull Predicate<? super Throwable> predicate)
Returns a
Maybe instance that if this Single emits an error and the predicate returns
true , it will emit an onComplete and swallow the throwable. |
@NonNull Single<T> |
onErrorResumeNext(@NonNull Function<? super Throwable,? extends SingleSource<? extends T>> fallbackSupplier)
Resumes the flow with a
SingleSource returned for the failure Throwable of the current Single by a
function instead of signaling the error via onError . |
@NonNull Single<T> |
onErrorResumeWith(@NonNull SingleSource<? extends T> fallback)
Resumes the flow with the given
SingleSource when the current Single fails instead of
signaling the error via onError . |
@NonNull Single<T> |
onErrorReturn(@NonNull Function<Throwable,? extends T> itemSupplier)
Ends the flow with a success item returned by a function for the
Throwable error signaled by the current
Single instead of signaling the error via onError . |
@NonNull Single<T> |
onErrorReturnItem(T item)
Signals the specified value as success in case the current
Single signals an error. |
@NonNull Single<T> |
onTerminateDetach()
Nulls out references to the upstream producer and downstream
SingleObserver if
the sequence is terminated or downstream calls dispose() . |
@NonNull Flowable<T> |
repeat()
Repeatedly re-subscribes to the current
Single and emits each success value as a Flowable sequence. |
@NonNull Flowable<T> |
repeat(long times)
Re-subscribes to the current
Single at most the given number of times and emits each success value as a Flowable sequence. |
@NonNull Flowable<T> |
repeatUntil(@NonNull BooleanSupplier stop)
Re-subscribes to the current
Single until the given BooleanSupplier returns true
and emits the success items as a Flowable sequence. |
@NonNull Flowable<T> |
repeatWhen(@NonNull Function<? super Flowable<Object>,? extends Publisher<?>> handler)
|
@NonNull Single<T> |
retry()
Repeatedly re-subscribes to the current
Single indefinitely if it fails with an onError . |
@NonNull Single<T> |
retry(@NonNull BiPredicate<? super Integer,? super Throwable> predicate)
Re-subscribe to the current
Single if the given predicate returns true when the Single fails
with an onError . |
@NonNull Single<T> |
retry(long times)
Repeatedly re-subscribe at most the specified times to the current
Single
if it fails with an onError . |
@NonNull Single<T> |
retry(long times,
@NonNull Predicate<? super Throwable> predicate)
Repeatedly re-subscribe at most times or until the predicate returns
false , whichever happens first
if it fails with an onError . |
@NonNull Single<T> |
retry(@NonNull Predicate<? super Throwable> predicate)
Re-subscribe to the current
Single if the given predicate returns true when the Single fails
with an onError . |
@NonNull Single<T> |
retryUntil(@NonNull BooleanSupplier stop)
Retries until the given stop function returns
true . |
@NonNull Single<T> |
retryWhen(@NonNull Function<? super Flowable<Throwable>,? extends Publisher<?>> handler)
Re-subscribes to the current
Single if and when the Publisher returned by the handler
function signals a value. |
void |
safeSubscribe(@NonNull SingleObserver<? super T> observer)
Wraps the given
SingleObserver , catches any RuntimeException s thrown by its
SingleObserver.onSubscribe(Disposable) , SingleObserver.onSuccess(Object) or
SingleObserver.onError(Throwable) methods* and routes those to the global error handler
via RxJavaPlugins.onError(Throwable) . |
static <T> @NonNull Single<Boolean> |
sequenceEqual(@NonNull SingleSource<? extends T> source1,
@NonNull SingleSource<? extends T> source2)
Compares two
SingleSource s and emits true if they emit the same value (compared via Object.equals(Object) ). |
@NonNull Flowable<T> |
startWith(@NonNull CompletableSource other)
Returns a
Flowable which first runs the other CompletableSource
then the current Single if the other completed normally. |
@NonNull Flowable<T> |
startWith(@NonNull MaybeSource<T> other)
Returns a
Flowable which first runs the other MaybeSource
then the current Single if the other succeeded or completed normally. |
@NonNull Observable<T> |
startWith(@NonNull ObservableSource<T> other)
Returns an
Observable which first delivers the events
of the other ObservableSource then runs the current Single . |
@NonNull Flowable<T> |
startWith(@NonNull Publisher<T> other)
|
@NonNull Flowable<T> |
startWith(@NonNull SingleSource<T> other)
Returns a
Flowable which first runs the other SingleSource
then the current Single if the other succeeded normally. |
@NonNull Disposable |
subscribe()
Subscribes to a
Single but ignore its emission or notification. |
@NonNull Disposable |
subscribe(@NonNull BiConsumer<? super T,? super Throwable> onCallback)
Subscribes to a
Single and provides a composite callback to handle the item it emits
or any error notification it issues. |
@NonNull Disposable |
subscribe(@NonNull Consumer<? super T> onSuccess)
Subscribes to a
Single and provides a callback to handle the item it emits. |
@NonNull Disposable |
subscribe(@NonNull Consumer<? super T> onSuccess,
@NonNull Consumer<? super Throwable> onError)
Subscribes to a
Single and provides callbacks to handle the item it emits or any error notification it
issues. |
@NonNull Disposable |
subscribe(@NonNull Consumer<? super T> onSuccess,
@NonNull Consumer<? super Throwable> onError,
@NonNull DisposableContainer container)
Wraps the given onXXX callbacks into a
Disposable SingleObserver ,
adds it to the given DisposableContainer and ensures, that if the upstream
terminates or this particular Disposable is disposed, the SingleObserver is removed
from the given container. |
void |
subscribe(@NonNull SingleObserver<? super T> observer)
Subscribes the given
SingleObserver to this SingleSource instance. |
protected abstract void |
subscribeActual(@NonNull SingleObserver<? super T> observer)
Implement this method in subclasses to handle the incoming
SingleObserver s. |
@NonNull Single<T> |
subscribeOn(@NonNull Scheduler scheduler)
|
<E extends SingleObserver<? super T>> |
subscribeWith(E observer)
Subscribes a given
SingleObserver (subclass) to this Single and returns the given
SingleObserver as is. |
static <T> @NonNull Flowable<T> |
switchOnNext(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Switches between
SingleSource s emitted by the source Publisher whenever
a new SingleSource is emitted, disposing the previously running SingleSource ,
exposing the success items as a Flowable sequence. |
static <T> @NonNull Flowable<T> |
switchOnNextDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Switches between
SingleSource s emitted by the source Publisher whenever
a new SingleSource is emitted, disposing the previously running SingleSource ,
exposing the success items as a Flowable sequence and delaying all errors from
all of them until all terminate. |
@NonNull Single<T> |
takeUntil(@NonNull CompletableSource other)
Returns a
Single that emits the item emitted by the current Single until a CompletableSource terminates. |
<E> @NonNull Single<T> |
takeUntil(@NonNull Publisher<E> other)
Returns a
Single that emits the item emitted by the current Single until a Publisher emits an item or completes. |
<E> @NonNull Single<T> |
takeUntil(@NonNull SingleSource<? extends E> other)
Returns a
Single that emits the item emitted by the current Single until a second Single emits an item. |
@NonNull TestObserver<T> |
test()
Creates a
TestObserver and subscribes it to this Single . |
@NonNull TestObserver<T> |
test(boolean dispose)
Creates a
TestObserver optionally in cancelled state, then subscribes it to this Single . |
@NonNull Single<Timed<T>> |
timeInterval()
Measures the time (in milliseconds) between the subscription and success item emission
of the current
Single 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 current
Single and signals it as a tuple (Timed )
success value. |
@NonNull Single<Timed<T>> |
timeInterval(@NonNull TimeUnit unit)
Measures the time between the subscription and success item emission
of the current
Single and signals it as a tuple (Timed )
success value. |
@NonNull Single<Timed<T>> |
timeInterval(@NonNull TimeUnit unit,
@NonNull Scheduler scheduler)
Measures the time between the subscription and success item emission
of the current
Single and signals it as a tuple (Timed )
success value. |
@NonNull Single<T> |
timeout(long timeout,
@NonNull TimeUnit unit)
Signals a
TimeoutException if the current Single doesn't signal a success value within the
specified timeout window. |
@NonNull Single<T> |
timeout(long timeout,
@NonNull TimeUnit unit,
@NonNull Scheduler scheduler)
Signals a
TimeoutException if the current Single doesn't signal a success value within the
specified timeout window. |
@NonNull Single<T> |
timeout(long timeout,
@NonNull TimeUnit unit,
@NonNull Scheduler scheduler,
@NonNull SingleSource<? extends T> fallback)
Runs the current
Single and if it doesn't signal within the specified timeout window, it is
disposed and the other SingleSource subscribed to. |
@NonNull Single<T> |
timeout(long timeout,
@NonNull TimeUnit unit,
@NonNull SingleSource<? extends T> fallback)
Runs the current
Single and if it doesn't signal within the specified timeout window, it is
disposed and the other SingleSource subscribed to. |
static @NonNull Single<Long> |
timer(long delay,
@NonNull TimeUnit unit)
Signals success with 0L value after the given delay when a
SingleObserver subscribes. |
static @NonNull Single<Long> |
timer(long delay,
@NonNull TimeUnit unit,
@NonNull Scheduler scheduler)
Signals success with 0L value on the specified
Scheduler after the given
delay when a SingleObserver subscribes. |
@NonNull Single<Timed<T>> |
timestamp()
|
@NonNull Single<Timed<T>> |
timestamp(@NonNull Scheduler scheduler)
|
@NonNull Single<Timed<T>> |
timestamp(@NonNull TimeUnit unit)
|
@NonNull Single<Timed<T>> |
timestamp(@NonNull TimeUnit unit,
@NonNull Scheduler scheduler)
|
<R> R |
to(@NonNull SingleConverter<T,? extends R> converter)
Calls the specified converter function during assembly time and returns its resulting value.
|
@NonNull CompletionStage<T> |
toCompletionStage()
Signals the upstream success item (or error) via a
CompletionStage . |
@NonNull Flowable<T> |
toFlowable()
Converts this
Single into a Flowable . |
@NonNull Future<T> |
toFuture()
Returns a
Future representing the single value emitted by this Single . |
@NonNull Maybe<T> |
toMaybe()
Converts this
Single into a Maybe . |
@NonNull Observable<T> |
toObservable()
Converts this
Single into an Observable . |
static <T> @NonNull Single<T> |
unsafeCreate(@NonNull SingleSource<T> onSubscribe)
Advanced use only: creates a
Single instance without
any safeguards by using a callback that is called with a SingleObserver . |
@NonNull Single<T> |
unsubscribeOn(@NonNull Scheduler scheduler)
Returns a
Single which makes sure when a SingleObserver disposes the Disposable ,
that call is propagated up on the specified Scheduler . |
static <T,U> @NonNull Single<T> |
using(@NonNull Supplier<U> resourceSupplier,
@NonNull Function<? super U,? extends SingleSource<? extends T>> sourceSupplier,
@NonNull Consumer<? super U> resourceCleanup)
Allows using and disposing a resource while running a
SingleSource instance generated from
that resource (similar to a try-with-resources). |
static <T,U> @NonNull Single<T> |
using(@NonNull Supplier<U> resourceSupplier,
@NonNull Function<? super U,? extends SingleSource<? extends T>> sourceSupplier,
@NonNull Consumer<? super U> resourceCleanup,
boolean eager)
Allows using and disposing a resource while running a
SingleSource instance generated from
that resource (similar to a try-with-resources). |
static <T> @NonNull Single<T> |
wrap(@NonNull SingleSource<T> source)
|
static <T,R> @NonNull Single<R> |
zip(@NonNull Iterable<? extends SingleSource<? extends T>> sources,
@NonNull Function<? super Object[],? extends R> zipper)
Waits until all
SingleSource sources provided by the Iterable 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 <T1,T2,R> @NonNull Single<R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull BiFunction<? super T1,? super T2,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to two items emitted by
two other SingleSource s. |
static <T1,T2,T3,R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull SingleSource<? extends T3> source3,
@NonNull Function3<? super T1,? super T2,? super T3,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to three items emitted
by three other SingleSource s. |
static <T1,T2,T3,T4,R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull SingleSource<? extends T3> source3,
@NonNull SingleSource<? extends T4> source4,
@NonNull Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to four items
emitted by four other SingleSource s. |
static <T1,T2,T3,T4,T5,R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull SingleSource<? extends T3> source3,
@NonNull SingleSource<? extends T4> source4,
@NonNull SingleSource<? extends T5> source5,
@NonNull Function5<? super T1,? super T2,? super T3,? super T4,? super T5,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to five items
emitted by five other SingleSource s. |
static <T1,T2,T3,T4,T5,T6,R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull SingleSource<? extends T3> source3,
@NonNull SingleSource<? extends T4> source4,
@NonNull SingleSource<? extends T5> source5,
@NonNull SingleSource<? extends T6> source6,
@NonNull Function6<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to six items
emitted by six other SingleSource s. |
static <T1,T2,T3,T4,T5,T6,T7,R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull SingleSource<? extends T3> source3,
@NonNull SingleSource<? extends T4> source4,
@NonNull SingleSource<? extends T5> source5,
@NonNull SingleSource<? extends T6> source6,
@NonNull SingleSource<? extends T7> source7,
@NonNull Function7<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to seven items
emitted by seven other SingleSource s. |
static <T1,T2,T3,T4,T5,T6,T7,T8,R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull SingleSource<? extends T3> source3,
@NonNull SingleSource<? extends T4> source4,
@NonNull SingleSource<? extends T5> source5,
@NonNull SingleSource<? extends T6> source6,
@NonNull SingleSource<? extends T7> source7,
@NonNull SingleSource<? extends T8> source8,
@NonNull Function8<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to eight items
emitted by eight other SingleSource s. |
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,R> |
zip(@NonNull SingleSource<? extends T1> source1,
@NonNull SingleSource<? extends T2> source2,
@NonNull SingleSource<? extends T3> source3,
@NonNull SingleSource<? extends T4> source4,
@NonNull SingleSource<? extends T5> source5,
@NonNull SingleSource<? extends T6> source6,
@NonNull SingleSource<? extends T7> source7,
@NonNull SingleSource<? extends T8> source8,
@NonNull SingleSource<? extends T9> source9,
@NonNull Function9<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? super T9,? extends R> zipper)
Returns a
Single that emits the results of a specified combiner function applied to nine items
emitted by nine other SingleSource s. |
static <T,R> @NonNull Single<R> |
zipArray(@NonNull Function<? super Object[],? extends R> zipper,
SingleSource<? extends T>... sources)
Waits until all
SingleSource 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. |
<U,R> @NonNull Single<R> |
zipWith(@NonNull SingleSource<U> other,
@NonNull BiFunction<? super T,? super U,? extends R> zipper)
Returns a
Single that emits the result of applying a specified function to the pair of items emitted by
the current Single and another specified SingleSource . |
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> amb(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
SingleSource
s and signals the events of the first one that signals (disposing
the rest).
amb
does not operate by default on a particular Scheduler
.T
- the value typesources
- the Iterable
sequence of sources. A subscription to each source will
occur in the same order as in this Iterable
.Single
instanceNullPointerException
- if sources
is null
@CheckReturnValue @SchedulerSupport(value="none") @SafeVarargs @NonNull public static <T> @NonNull Single<T> ambArray(@NonNull SingleSource<? extends T>... sources)
SingleSource
s and signals the events of the first one that signals (disposing
the rest).
ambArray
does not operate by default on a particular Scheduler
.T
- the value typesources
- the array of sources. A subscription to each source will
occur in the same order as in this array.Single
instanceNullPointerException
- if sources
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") @BackpressureSupport(value=FULL) public static <T> @NonNull Flowable<T> concat(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
SingleSource
s provided by
an Iterable
sequence.
T
- the value typesources
- the Iterable
sequence of SingleSource
instancesFlowable
instanceNullPointerException
- if sources
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Observable<T> concat(@NonNull ObservableSource<? extends SingleSource<? extends T>> sources)
SingleSource
s provided by
an ObservableSource
sequence.
concat
does not operate by default on a particular Scheduler
.T
- the value typesources
- the ObservableSource
of SingleSource
instancesObservable
instanceNullPointerException
- if sources
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concat(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
SingleSource
s provided by
a Publisher
sequence.
T
- the value typesources
- the Publisher
of SingleSource
instancesFlowable
instanceNullPointerException
- if sources
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concat(@NonNull Publisher<? extends SingleSource<? extends T>> sources, int prefetch)
SingleSource
s provided by
a Publisher
sequence and prefetched by the specified amount.
T
- the value typesources
- the Publisher
of SingleSource
instancesprefetch
- the number of SingleSource
s to prefetch from the Publisher
Flowable
instanceNullPointerException
- if sources
is null
IllegalArgumentException
- if prefetch
is non-positive@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concat(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2)
Flowable
that emits the items emitted by two SingleSource
s, one after the other.
Flowable
honors the backpressure of the downstream consumer.concat
does not operate by default on a particular Scheduler
.T
- the common value typesource1
- a SingleSource
to be concatenatedsource2
- a SingleSource
to be concatenatedFlowable
instanceNullPointerException
- if source1
or source2
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concat(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2, @NonNull SingleSource<? extends T> source3)
Flowable
that emits the items emitted by three SingleSource
s, one after the other.
Flowable
honors the backpressure of the downstream consumer.concat
does not operate by default on a particular Scheduler
.T
- the common value typesource1
- a SingleSource
to be concatenatedsource2
- a SingleSource
to be concatenatedsource3
- a SingleSource
to be concatenatedFlowable
instanceNullPointerException
- if source1
, source2
or source3
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concat(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2, @NonNull SingleSource<? extends T> source3, @NonNull SingleSource<? extends T> source4)
Flowable
that emits the items emitted by four SingleSource
s, one after the other.
Flowable
honors the backpressure of the downstream consumer.concat
does not operate by default on a particular Scheduler
.T
- the common value typesource1
- a SingleSource
to be concatenatedsource2
- a SingleSource
to be concatenatedsource3
- a SingleSource
to be concatenatedsource4
- a SingleSource
to be concatenatedFlowable
instanceNullPointerException
- if source1
, source2
, source3
or source4
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") @SafeVarargs public static <T> @NonNull Flowable<T> concatArray(@NonNull SingleSource<? extends T>... sources)
SingleSource
s provided in
an array.
T
- the value typesources
- the array of SingleSource
instancesFlowable
instanceNullPointerException
- if sources
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") @SafeVarargs public static <T> @NonNull Flowable<T> concatArrayDelayError(@NonNull SingleSource<? extends T>... sources)
SingleSource
s provided in
an array.
T
- the value typesources
- the array of SingleSource
instancesFlowable
instanceNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") @SafeVarargs public static <T> @NonNull Flowable<T> concatArrayEager(@NonNull SingleSource<? extends T>... sources)
SingleSource
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 these SingleSource
s and then drains them
in order, each one after the previous one succeeds.
Scheduler
.T
- the value typesources
- a sequence of SingleSource
s that need to be eagerly concatenatedFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") @SafeVarargs public static <T> @NonNull Flowable<T> concatArrayEagerDelayError(@NonNull SingleSource<? extends T>... sources)
SingleSource
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 these SingleSource
s and then drains them
in order, each one after the previous one succeeds.
Scheduler
.T
- the value typesources
- a sequence of SingleSource
s that need to be eagerly concatenatedFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Iterable
sequence of SingleSource
s into a single sequence by subscribing to each SingleSource
,
one after the other, one at a time and delays any errors till the all inner SingleSource
s terminate
as a Flowable
sequence.
concatDelayError
does not operate by default on a particular Scheduler
.T
- the common element base typesources
- the Iterable
sequence of SingleSource
sFlowable
with the concatenating behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T> @NonNull Flowable<T> concatDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Publisher
sequence of SingleSource
s into a single sequence by subscribing to each inner SingleSource
,
one after the other, one at a time and delays any errors till the all inner and the outer Publisher
terminate
as a Flowable
sequence.
concatDelayError
fully supports backpressure.concatDelayError
does not operate by default on a particular Scheduler
.T
- the common element base typesources
- the Publisher
sequence of SingleSource
sFlowable
with the concatenating behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T> @NonNull Flowable<T> concatDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources, int prefetch)
Publisher
sequence of SingleSource
s into a single sequence by subscribing to each inner SingleSource
,
one after the other, one at a time and delays any errors till the all inner and the outer Publisher
terminate
as a Flowable
sequence.
concatDelayError
fully supports backpressure.concatDelayError
does not operate by default on a particular Scheduler
.T
- the common element base typesources
- the Publisher
sequence of SingleSource
sprefetch
- The number of upstream items to prefetch so that fresh items are
ready to be mapped when a previous SingleSource
terminates.
The operator replenishes after half of the prefetch amount has been consumed
and turned into SingleSource
s.Flowable
with the concatenating behaviorNullPointerException
- if sources
is null
IllegalArgumentException
- if prefetch
is non-positive@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEager(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Iterable
sequence of SingleSource
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 these SingleSource
s and then drains them
in order, each one after the previous one succeeds.
Scheduler
.T
- the value typesources
- an Iterable
sequence of SingleSource
that need to be eagerly concatenatedFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEager(@NonNull Iterable<? extends SingleSource<? extends T>> sources, int maxConcurrency)
Iterable
sequence of SingleSource
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 these SingleSource
s and then drains them
in order, each one after the previous one succeeds.
Scheduler
.T
- the value typesources
- an Iterable
sequence of SingleSource
that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running inner SingleSource
s; Integer.MAX_VALUE
is interpreted as all inner SingleSource
s can be active at the same timeFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
IllegalArgumentException
- if maxConcurrency
is non-positive@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEager(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Publisher
sequence of SingleSource
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 these
SingleSource
s and then drains them in order, each one after the previous one succeeds.
Publisher
is
expected to support backpressure. Violating this assumption, the operator will
signal MissingBackpressureException
.Scheduler
.T
- the value typesources
- a sequence of SingleSource
s that need to be eagerly concatenatedFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEager(@NonNull Publisher<? extends SingleSource<? extends T>> sources, int maxConcurrency)
Publisher
sequence of SingleSource
s eagerly into a single stream of values and
runs a limited number of those inner SingleSource
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 these
SingleSource
s and then drains them in order, each one after the previous one succeeds.
Publisher
is
expected to support backpressure. Violating this assumption, the operator will
signal MissingBackpressureException
.Scheduler
.T
- the value typesources
- a sequence of SingleSource
s that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running inner SingleSource
s; Integer.MAX_VALUE
is interpreted as all inner SingleSource
s can be active at the same timeFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
IllegalArgumentException
- if maxConcurrency
is non-positive@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEagerDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Iterable
sequence of SingleSource
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 these SingleSource
s and then drains them
in order, each one after the previous one succeeds.
Scheduler
.T
- the value typesources
- an Iterable
sequence of SingleSource
that need to be eagerly concatenatedFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEagerDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources, int maxConcurrency)
Iterable
sequence of SingleSource
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 these SingleSource
s and then drains them
in order, each one after the previous one succeeds.
Scheduler
.T
- the value typesources
- an Iterable
sequence of SingleSource
that need to be eagerly concatenatedmaxConcurrency
- the maximum number of concurrently running inner SingleSource
s; Integer.MAX_VALUE
is interpreted as all inner SingleSource
s can be active at the same timeFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
IllegalArgumentException
- if maxConcurrency
is non-positive@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEagerDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
Publisher
sequence of SingleSource
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 these
SingleSource
s and then drains them in order, each one after the previous one succeeds.
Publisher
is
expected to support backpressure. Violating this assumption, the operator will
signal MissingBackpressureException
.Scheduler
.T
- the value typesources
- a sequence of SingleSource
s that need to be eagerly concatenatedFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> concatEagerDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources, int maxConcurrency)
Publisher
sequence of SingleSource
s eagerly into a single stream of values,
running at most the specified number of those inner SingleSource
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 these
SingleSource
s and then drains them in order, each one after the previous one succeeds.
Publisher
is
expected to support backpressure. Violating this assumption, the operator will
signal MissingBackpressureException
.Scheduler
.T
- the value typesources
- a sequence of SingleSource
s that need to be eagerly concatenatedmaxConcurrency
- the number of inner SingleSource
s to run at onceFlowable
instance with the specified concatenation behaviorNullPointerException
- if sources
is null
IllegalArgumentException
- if maxConcurrency
is non-positive@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> create(@NonNull SingleOnSubscribe<T> source)
Single
) 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 returned Single
, the provided
SingleOnSubscribe
callback is invoked with a fresh instance of a SingleEmitter
that will interact only with that specific SingleObserver
. If this SingleObserver
disposes the flow (making SingleEmitter.isDisposed()
return true
),
other observers subscribed to the same returned Single
are not affected.
create
does not operate by default on a particular Scheduler
.T
- the value typesource
- the emitter that is called when a SingleObserver
subscribes to the returned Single
Single
instanceNullPointerException
- if source
is null
SingleOnSubscribe
,
Cancellable
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> defer(@NonNull Supplier<? extends SingleSource<? extends T>> supplier)
Supplier
for each individual SingleObserver
to return the actual SingleSource
to
be subscribed to.
defer
does not operate by default on a particular Scheduler
.T
- the value typesupplier
- the Supplier
that is called for each individual SingleObserver
and
returns a SingleSource
instance to subscribe toSingle
instanceNullPointerException
- if supplier
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> error(@NonNull Supplier<? extends Throwable> supplier)
Throwable
returned by the callback function for each individual SingleObserver
.
error
does not operate by default on a particular Scheduler
.T
- the value typesupplier
- the Supplier
that is called for each individual SingleObserver
and
returns a Throwable
instance to be emitted.Single
instanceNullPointerException
- if supplier
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> error(@NonNull Throwable throwable)
Single
that invokes a subscriber's onError
method when the
subscriber subscribes to it.
error
does not operate by default on a particular Scheduler
.T
- the type of the item (ostensibly) emitted by the Single
throwable
- the particular Throwable
to pass to onError
Single
that invokes the subscriber's onError
method when
the subscriber subscribes to itNullPointerException
- if throwable
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> fromCallable(@NonNull Callable<? extends T> callable)
Single
that invokes the given Callable
for each incoming SingleObserver
and emits its value or exception to them.
Allows you to defer execution of passed function until SingleObserver
subscribes to the Single
.
It makes passed function "lazy".
Result of the function invocation will be emitted by the Single
.
fromCallable
does not operate by default on a particular Scheduler
.Callable
throws an exception, the respective Throwable
is
delivered to the downstream via SingleObserver.onError(Throwable)
,
except when the downstream has disposed this Single
source.
In this latter case, the Throwable
is delivered to the global error handler via
RxJavaPlugins.onError(Throwable)
as an UndeliverableException
.
T
- the type of the item emitted by the Single
.callable
- function which execution should be deferred, it will be invoked when SingleObserver
will subscribe to the Single
.Single
whose SingleObserver
s' subscriptions trigger an invocation of the given function.NullPointerException
- if callable
is null
defer(Supplier)
,
fromSupplier(Supplier)
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T> @NonNull Single<T> fromFuture(@NonNull Future<? extends T> future)
Future
into a Single
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 applying subscribeOn(Scheduler)
to move this blocking wait to a
background thread, and if the Scheduler
supports it, interrupt the wait when the flow
is disposed.
A non-null
value is then emitted via onSuccess
or any exception is emitted via
onError
. If the Future
completes with null
, a NullPointerException
is signaled.
fromFuture
does not operate by default on a particular Scheduler
.T
- the type of object that the Future
returns, and also the type of item to be emitted by
the resulting Single
future
- the source Future
Single
that emits the item from the source Future
NullPointerException
- if future
is null
fromFuture(Future, long, TimeUnit)
,
fromCompletionStage(CompletionStage)
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T> @NonNull Single<T> fromFuture(@NonNull Future<? extends T> future, long timeout, @NonNull TimeUnit unit)
Future
into a Single
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 applying subscribeOn(Scheduler)
to move this blocking wait to a
background thread, and if the Scheduler
supports it, interrupt the wait when the flow
is disposed.
A non-null
value is then emitted via onSuccess
or any exception is emitted via
onError
. If the Future
completes with null
, a NullPointerException
is signaled.
fromFuture
does not operate by default on a particular Scheduler
.T
- the type of object that the Future
returns, and also the type of item to be emitted by
the resulting Single
future
- the source Future
timeout
- the maximum time to wait before calling get
unit
- the TimeUnit
of the timeout
argumentSingle
that emits the item from the source Future
NullPointerException
- if future
or unit
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> fromMaybe(@NonNull MaybeSource<T> maybe)
Single
instance that when subscribed to, subscribes to the MaybeSource
instance and
emits onSuccess
as a single item, turns an onComplete
into NoSuchElementException
error signal or
forwards the onError
signal.
fromMaybe
does not operate by default on a particular Scheduler
.T
- the value type of the MaybeSource
elementmaybe
- the MaybeSource
instance to subscribe to, not null
Single
instanceNullPointerException
- if maybe
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> fromMaybe(@NonNull MaybeSource<T> maybe, @NonNull T defaultItem)
Single
instance that when subscribed to, subscribes to the MaybeSource
instance and
emits onSuccess
as a single item, emits the defaultItem
for an onComplete
signal or
forwards the onError
signal.
fromMaybe
does not operate by default on a particular Scheduler
.T
- the value type of the MaybeSource
elementmaybe
- the MaybeSource
instance to subscribe to, not null
defaultItem
- the item to signal if the current MaybeSource
is emptySingle
instanceNullPointerException
- if maybe
or defaultItem
is null
@BackpressureSupport(value=UNBOUNDED_IN) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> fromPublisher(@NonNull Publisher<? extends T> publisher)
Publisher
into a Single
and signals its single element or error.
If the source Publisher
is empty, a NoSuchElementException
is signaled. If
the source has more than one element, an IndexOutOfBoundsException
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-like Single
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.
publisher
is consumed in an unbounded fashion but will be cancelled
if it produced more than one item.fromPublisher
does not operate by default on a particular Scheduler
.T
- the value typepublisher
- the source Publisher
instance, not null
Single
instanceNullPointerException
- if publisher
is null
create(SingleOnSubscribe)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> fromObservable(@NonNull ObservableSource<? extends T> observable)
ObservableSource
into a Single
and signals its single element or error.
If the ObservableSource
is empty, a NoSuchElementException
is signaled.
If the source has more than one element, an IndexOutOfBoundsException
is signaled.
fromObservable
does not operate by default on a particular Scheduler
.T
- the type of the item emitted by the Single
.observable
- the source sequence to wrap, not null
Single
instanceNullPointerException
- if observable
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> fromSupplier(@NonNull Supplier<? extends T> supplier)
Single
that invokes passed supplier and emits its result
for each individual SingleObserver
that subscribes.
Allows you to defer execution of passed function until a SingleObserver
subscribes to the Single
.
It makes passed function "lazy".
Result of the function invocation will be emitted by the Single
.
fromSupplier
does not operate by default on a particular Scheduler
.Supplier
throws an exception, the respective Throwable
is
delivered to the downstream via SingleObserver.onError(Throwable)
,
except when the downstream has disposed this Single
source.
In this latter case, the Throwable
is delivered to the global error handler via
RxJavaPlugins.onError(Throwable)
as an UndeliverableException
.
T
- the type of the item emitted by the Single
.supplier
- function which execution should be deferred, it will be invoked when SingleObserver
subscribes to the Single
.Single
whose SingleObserver
s' subscriptions trigger an invocation of the given function.NullPointerException
- if supplier
is null
defer(Supplier)
,
fromCallable(Callable)
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T> @NonNull Single<T> just(T item)
Single
that emits a specified item.
To convert any object into a Single
that emits that object, pass that object into the
just
method.
just
does not operate by default on a particular Scheduler
.T
- the type of that itemitem
- the item to emitSingle
that emits item
NullPointerException
- if item
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> merge(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Iterable
sequence of SingleSource
instances into a single Flowable
sequence,
running all SingleSource
s at once.
Flowable
honors the backpressure of the downstream consumer.merge
does not operate by default on a particular Scheduler
.SingleSource
s signal a Throwable
via onError
, the resulting
Flowable
terminates with that Throwable
and all other source SingleSource
s are disposed.
If more than one SingleSource
signals an error, the resulting Flowable
may terminate with the
first one's error or, depending on the concurrency of the sources, may terminate with a
CompositeException
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 via
RxJavaPlugins.onError(Throwable)
method as UndeliverableException
errors. Similarly, Throwable
s
signaled by source(s) after the returned Flowable
has been cancelled or terminated with a
(composite) error will be sent to the same global error handler.
Use mergeDelayError(Iterable)
to merge sources and terminate only when all source SingleSource
s
have completed or failed with an error.
T
- the common and resulting value typesources
- the Iterable
sequence of SingleSource
sourcesFlowable
instanceNullPointerException
- if sources
is null
mergeDelayError(Iterable)
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> merge(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
SingleSource
instances emitted by a Publisher
into a single Flowable
sequence,
running all SingleSource
s at once.
Flowable
honors the backpressure of the downstream consumer.merge
does not operate by default on a particular Scheduler
.SingleSource
s signal a Throwable
via onError
, the resulting
Flowable
terminates with that Throwable
and all other source SingleSource
s are disposed.
If more than one SingleSource
signals an error, the resulting Flowable
may terminate with the
first one's error or, depending on the concurrency of the sources, may terminate with a
CompositeException
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 via
RxJavaPlugins.onError(Throwable)
method as UndeliverableException
errors. Similarly, Throwable
s
signaled by source(s) after the returned Flowable
has been cancelled or terminated with a
(composite) error will be sent to the same global error handler.
Use mergeDelayError(Publisher)
to merge sources and terminate only when all source SingleSource
s
have completed or failed with an error.
T
- the common and resulting value typesources
- the Publisher
emitting a sequence of SingleSource
sFlowable
instanceNullPointerException
- if sources
is null
mergeDelayError(Publisher)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> merge(@NonNull SingleSource<? extends SingleSource<? extends T>> source)
SingleSource
that emits a SingleSingle
into a single Single
that emits the item
emitted by the nested SingleSource
, without any transformation.
merge
does not operate by default on a particular Scheduler
.Single
emits the outer source's or the inner SingleSource
's Throwable
as is.
Unlike the other merge()
operators, this operator won't and can't produce a CompositeException
because there is
only one possibility for the outer or the inner SingleSource
to emit an onError
signal.
Therefore, there is no need for a mergeDelayError(SingleSource<SingleSource<T>>)
operator.
T
- the value type of the sources and the outputsource
- a Single
that emits a Single
Single
that emits the item that is the result of flattening the Single
emitted
by source
NullPointerException
- if source
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> merge(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2)
SingleSource
s into one Flowable
sequence, without any transformation.
You can combine items emitted by multiple SingleSource
s so that they appear as a single Flowable
, by
using the merge
method.
Flowable
honors the backpressure of the downstream consumer.merge
does not operate by default on a particular Scheduler
.SingleSource
s signal a Throwable
via onError
, the resulting
Flowable
terminates with that Throwable
and all other source SingleSource
s are disposed.
If more than one SingleSource
signals an error, the resulting Flowable
may terminate with the
first one's error or, depending on the concurrency of the sources, may terminate with a
CompositeException
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 via
RxJavaPlugins.onError(Throwable)
method as UndeliverableException
errors. Similarly, Throwable
s
signaled by source(s) after the returned Flowable
has been cancelled or terminated with a
(composite) error will be sent to the same global error handler.
Use mergeDelayError(SingleSource, SingleSource)
to merge sources and terminate only when all source SingleSource
s
have completed or failed with an error.
T
- the common value typesource1
- a SingleSource
to be mergedsource2
- a SingleSource
to be mergedFlowable
that emits all of the items emitted by the source SingleSource
sNullPointerException
- if source1
or source2
is null
mergeDelayError(SingleSource, SingleSource)
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> merge(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2, @NonNull SingleSource<? extends T> source3)
SingleSource
s into one Flowable
sequence, without any transformation.
You can combine items emitted by multiple SingleSource
s so that they appear as a single Flowable
, by
the merge
method.
Flowable
honors the backpressure of the downstream consumer.merge
does not operate by default on a particular Scheduler
.SingleSource
s signal a Throwable
via onError
, the resulting
Flowable
terminates with that Throwable
and all other source SingleSource
s are disposed.
If more than one SingleSource
signals an error, the resulting Flowable
may terminate with the
first one's error or, depending on the concurrency of the sources, may terminate with a
CompositeException
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 via
RxJavaPlugins.onError(Throwable)
method as UndeliverableException
errors. Similarly, Throwable
s
signaled by source(s) after the returned Flowable
has been cancelled or terminated with a
(composite) error will be sent to the same global error handler.
Use mergeDelayError(SingleSource, SingleSource, SingleSource)
to merge sources and terminate only when all source SingleSource
s
have completed or failed with an error.
T
- the common value typesource1
- a SingleSource
to be mergedsource2
- a SingleSource
to be mergedsource3
- a SingleSource
to be mergedFlowable
that emits all of the items emitted by the source SingleSource
sNullPointerException
- if source1
, source2
or source3
is null
mergeDelayError(SingleSource, SingleSource, SingleSource)
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> merge(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2, @NonNull SingleSource<? extends T> source3, @NonNull SingleSource<? extends T> source4)
SingleSource
s into one Flowable
sequence, without any transformation.
You can combine items emitted by multiple SingleSource
s so that they appear as a single Flowable
, by
the merge
method.
Flowable
honors the backpressure of the downstream consumer.merge
does not operate by default on a particular Scheduler
.SingleSource
s signal a Throwable
via onError
, the resulting
Flowable
terminates with that Throwable
and all other source SingleSource
s are disposed.
If more than one SingleSource
signals an error, the resulting Flowable
may terminate with the
first one's error or, depending on the concurrency of the sources, may terminate with a
CompositeException
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 via
RxJavaPlugins.onError(Throwable)
method as UndeliverableException
errors. Similarly, Throwable
s
signaled by source(s) after the returned Flowable
has been cancelled or terminated with a
(composite) error will be sent to the same global error handler.
Use mergeDelayError(SingleSource, SingleSource, SingleSource, SingleSource)
to merge sources and terminate only when all source SingleSource
s
have completed or failed with an error.
T
- the common value typesource1
- a SingleSource
to be mergedsource2
- a SingleSource
to be mergedsource3
- a SingleSource
to be mergedsource4
- a SingleSource
to be mergedFlowable
that emits all of the items emitted by the source SingleSource
sNullPointerException
- if source1
, source2
, source3
or source4
is null
mergeDelayError(SingleSource, SingleSource, SingleSource, SingleSource)
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") @SafeVarargs public static <T> @NonNull Flowable<T> mergeArray(SingleSource<? extends T>... sources)
SingleSource
instances into a single Flowable
sequence,
running all SingleSource
s at once.
mergeArray
does not operate by default on a particular Scheduler
.SingleSource
s signal a Throwable
via onError
, the resulting
Flowable
terminates with that Throwable
and all other source SingleSource
s are disposed.
If more than one SingleSource
signals an error, the resulting Flowable
may terminate with the
first one's error or, depending on the concurrency of the sources, may terminate with a
CompositeException
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 via
RxJavaPlugins.onError(Throwable)
method as UndeliverableException
errors. Similarly, Throwable
s
signaled by source(s) after the returned Flowable
has been cancelled or terminated with a
(composite) error will be sent to the same global error handler.
Use mergeArrayDelayError(SingleSource...)
to merge sources and terminate only when all source SingleSource
s
have completed or failed with an error.
T
- the common and resulting value typesources
- the array sequence of SingleSource
sourcesFlowable
instanceNullPointerException
- if sources
is null
mergeArrayDelayError(SingleSource...)
@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @SafeVarargs @NonNull public static <T> @NonNull Flowable<T> mergeArrayDelayError(@NonNull SingleSource<? extends T>... sources)
SingleSource
s into one Flowable
, in a way that allows a subscriber to receive all
successfully emitted items from each of the source SingleSource
s without being interrupted by an error
notification from one of them.
This behaves like merge(Publisher)
except that if any of the merged SingleSource
s notify of an
error via onError
, mergeArrayDelayError
will refrain from propagating that
error notification until all of the merged SingleSource
s have finished emitting items.
Even if multiple merged SingleSource
s send onError
notifications, mergeArrayDelayError
will only
invoke the onError
method of its subscribers once.
mergeArrayDelayError
does not operate by default on a particular Scheduler
.T
- the common element base typesources
- the array of SingleSource
sFlowable
instanceNullPointerException
- if sources
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> mergeDelayError(@NonNull Iterable<? extends SingleSource<? extends T>> sources)
Iterable
sequence of SingleSource
instances into one Flowable
sequence,
running all SingleSource
s at once and delaying any error(s) until all sources succeed or fail.
Flowable
honors the backpressure of the downstream consumer.mergeDelayError
does not operate by default on a particular Scheduler
.History: 2.1.9 - experimental
T
- the common and resulting value typesources
- the Iterable
sequence of SingleSource
sFlowable
instanceNullPointerException
- if sources
is null
merge(Iterable)
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> mergeDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
SingleSource
instances emitted by a Publisher
into a Flowable
sequence,
running all SingleSource
s at once and delaying any error(s) until all sources succeed or fail.
Flowable
honors the backpressure of the downstream consumer.mergeDelayError
does not operate by default on a particular Scheduler
.History: 2.1.9 - experimental
T
- the common and resulting value typesources
- the Flowable
sequence of SingleSource
sFlowable
instanceNullPointerException
- if sources
is null
merge(Publisher)
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> mergeDelayError(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2)
SingleSource
s into one Flowable
, 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 one Flowable
, by
using the mergeDelayError
method.
Flowable
honors the backpressure of the downstream consumer.mergeDelayError
does not operate by default on a particular Scheduler
.History: 2.1.9 - experimental
T
- the common value typesource1
- a SingleSource
to be mergedsource2
- a SingleSource
to be mergedFlowable
that emits all of the items emitted by the source SingleSource
sNullPointerException
- if source1
or source2
is null
merge(SingleSource, SingleSource)
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> mergeDelayError(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2, @NonNull SingleSource<? extends T> source3)
SingleSource
s into one Flowable
, 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 one Flowable
, by
the mergeDelayError
method.
Flowable
honors the backpressure of the downstream consumer.mergeDelayError
does not operate by default on a particular Scheduler
.History: 2.1.9 - experimental
T
- the common value typesource1
- a SingleSource
to be mergedsource2
- a SingleSource
to be mergedsource3
- a SingleSource
to be mergedFlowable
that emits all of the items emitted by the source SingleSource
sNullPointerException
- if source1
, source2
or source3
is null
merge(SingleSource, SingleSource, SingleSource)
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> mergeDelayError(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2, @NonNull SingleSource<? extends T> source3, @NonNull SingleSource<? extends T> source4)
SingleSource
s into one Flowable
, 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 one Flowable
, by
the mergeDelayError
method.
Flowable
honors the backpressure of the downstream consumer.mergeDelayError
does not operate by default on a particular Scheduler
.History: 2.1.9 - experimental
T
- the common value typesource1
- a SingleSource
to be mergedsource2
- a SingleSource
to be mergedsource3
- a SingleSource
to be mergedsource4
- a SingleSource
to be mergedFlowable
that emits all of the items emitted by the source SingleSource
sNullPointerException
- if source1
, source2
, source3
or source4
is null
merge(SingleSource, SingleSource, SingleSource, SingleSource)
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T> @NonNull Single<T> never()
Single
(only calls onSubscribe
).
never
does not operate by default on a particular Scheduler
.T
- the target value type@CheckReturnValue @SchedulerSupport(value="io.reactivex:computation") @NonNull public static @NonNull Single<Long> timer(long delay, @NonNull TimeUnit unit)
SingleObserver
subscribes.
timer
operates by default on the computation
Scheduler
.delay
- the delay amountunit
- the time unit of the delaySingle
instanceNullPointerException
- if unit
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public static @NonNull Single<Long> timer(long delay, @NonNull TimeUnit unit, @NonNull Scheduler scheduler)
Scheduler
after the given
delay when a SingleObserver
subscribes.
Scheduler
to signal on.delay
- the delay amountunit
- the time unit of the delayscheduler
- the Scheduler
where the single 0L will be emittedSingle
instanceNullPointerException
- if unit
is null
, or
if scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<Boolean> sequenceEqual(@NonNull SingleSource<? extends T> source1, @NonNull SingleSource<? extends T> source2)
SingleSource
s and emits true
if they emit the same value (compared via Object.equals(Object)
).
sequenceEqual
does not operate by default on a particular Scheduler
.T
- the common value typesource1
- the first SingleSource
instancesource2
- the second SingleSource
instanceSingle
instanceNullPointerException
- if source1
or source2
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> switchOnNext(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
SingleSource
s emitted by the source Publisher
whenever
a new SingleSource
is emitted, disposing the previously running SingleSource
,
exposing the success items as a Flowable
sequence.
sources
Publisher
is consumed in an unbounded manner (requesting Long.MAX_VALUE
).
The returned Flowable
respects the backpressure from the downstream.switchOnNext
does not operate by default on a particular Scheduler
.sources
Publisher
or the currently running SingleSource
, disposing the rest. Late errors are
forwarded to the global error handler via RxJavaPlugins.onError(Throwable)
.T
- the element type of the SingleSource
ssources
- the Publisher
sequence of inner SingleSource
s to switch betweenFlowable
instanceNullPointerException
- if sources
is null
switchOnNextDelayError(Publisher)
,
ReactiveX operators documentation: Switch@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Flowable<T> switchOnNextDelayError(@NonNull Publisher<? extends SingleSource<? extends T>> sources)
SingleSource
s emitted by the source Publisher
whenever
a new SingleSource
is emitted, disposing the previously running SingleSource
,
exposing the success items as a Flowable
sequence and delaying all errors from
all of them until all terminate.
sources
Publisher
is consumed in an unbounded manner (requesting Long.MAX_VALUE
).
The returned Flowable
respects the backpressure from the downstream.switchOnNextDelayError
does not operate by default on a particular Scheduler
.Flowable
collects all errors emitted by either the sources
Publisher
or any inner SingleSource
and emits them as a CompositeException
when all sources terminate. If only one source ever failed, its error is emitted as-is at the end.T
- the element type of the SingleSource
ssources
- the Publisher
sequence of inner SingleSource
s to switch betweenFlowable
instanceNullPointerException
- if sources
is null
switchOnNext(Publisher)
,
ReactiveX operators documentation: Switch@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> unsafeCreate(@NonNull SingleSource<T> onSubscribe)
Single
instance without
any safeguards by using a callback that is called with a SingleObserver
.
unsafeCreate
does not operate by default on a particular Scheduler
.T
- the value typeonSubscribe
- the function that is called with the subscribing SingleObserver
Single
instanceNullPointerException
- if onSubscribe
is null
IllegalArgumentException
- if source
is a subclass of Single
; such
instances don't need conversion and is possibly a port remnant from 1.x or one should use hide()
instead.@CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T,U> @NonNull Single<T> using(@NonNull Supplier<U> resourceSupplier, @NonNull Function<? super U,? extends SingleSource<? extends T>> sourceSupplier, @NonNull Consumer<? super U> resourceCleanup)
SingleSource
instance generated from
that resource (similar to a try-with-resources).
using
does not operate by default on a particular Scheduler
.T
- the value type of the SingleSource
generatedU
- the resource typeresourceSupplier
- the Supplier
called for each SingleObserver
to generate a resource objectsourceSupplier
- the function called with the returned resource
object from resourceSupplier
and should return a SingleSource
instance
to be run by the operatorresourceCleanup
- the consumer of the generated resource that is called exactly once for
that particular resource when the generated SingleSource
terminates
(successfully or with an error) or gets disposed.Single
instanceNullPointerException
- if resourceSupplier
, sourceSupplier
and resourceCleanup
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T,U> @NonNull Single<T> using(@NonNull Supplier<U> resourceSupplier, @NonNull Function<? super U,? extends SingleSource<? extends T>> sourceSupplier, @NonNull Consumer<? super U> resourceCleanup, boolean eager)
SingleSource
instance generated from
that resource (similar to a try-with-resources).
using
does not operate by default on a particular Scheduler
.T
- the value type of the SingleSource
generatedU
- the resource typeresourceSupplier
- the Supplier
called for each SingleObserver
to generate a resource objectsourceSupplier
- the function called with the returned resource
object from resourceSupplier
and should return a SingleSource
instance
to be run by the operatorresourceCleanup
- the consumer of the generated resource that is called exactly once for
that particular resource when the generated SingleSource
terminates
(successfully or with an error) or gets disposed.eager
- If true
then resource disposal will happen either on a dispose()
call before the upstream is disposed
or just before the emission of a terminal event (onSuccess
or onError
).
If false
the resource disposal will happen either on a dispose()
call after the upstream is disposed
or just after the emission of a terminal event (onSuccess
or onError
).Single
instanceNullPointerException
- if resourceSupplier
, sourceSupplier
or resourceCleanup
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T> @NonNull Single<T> wrap(@NonNull SingleSource<T> source)
SingleSource
instance into a new Single
instance if not already a Single
instance.
wrap
does not operate by default on a particular Scheduler
.T
- the value typesource
- the source to wrapSingle
instanceNullPointerException
- if source
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T,R> @NonNull Single<R> zip(@NonNull Iterable<? extends SingleSource<? extends T>> sources, @NonNull Function<? super Object[],? extends R> zipper)
SingleSource
sources provided by the Iterable
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
of SingleSource
s is empty a NoSuchElementException
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 an Object[]
instead. Unfortunately, a
Function<Integer[], R>
passed to the method would trigger a ClassCastException
.
If any of the SingleSources
signal an error, all other SingleSource
s get disposed and the
error emitted to downstream immediately.
zip
does not operate by default on a particular Scheduler
.T
- the common value typeR
- the result value typesources
- the Iterable
sequence of SingleSource
instances. An empty sequence will result in an
onError
signal of NoSuchElementException
.zipper
- the function that receives an array with values from each SingleSource
and should return a value to be emitted to downstreamSingle
instanceNullPointerException
- if zipper
or sources
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull BiFunction<? super T1,? super T2,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to two items emitted by
two other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,T3,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull SingleSource<? extends T3> source3, @NonNull Function3<? super T1,? super T2,? super T3,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to three items emitted
by three other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeT3
- the third source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
source3
- a third source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
, source3
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,T3,T4,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull SingleSource<? extends T3> source3, @NonNull SingleSource<? extends T4> source4, @NonNull Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to four items
emitted by four other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeT3
- the third source SingleSource
's value typeT4
- the fourth source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
source3
- a third source SingleSource
source4
- a fourth source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
, source3
, source4
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,T3,T4,T5,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull SingleSource<? extends T3> source3, @NonNull SingleSource<? extends T4> source4, @NonNull SingleSource<? extends T5> source5, @NonNull Function5<? super T1,? super T2,? super T3,? super T4,? super T5,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to five items
emitted by five other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeT3
- the third source SingleSource
's value typeT4
- the fourth source SingleSource
's value typeT5
- the fifth source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
source3
- a third source SingleSource
source4
- a fourth source SingleSource
source5
- a fifth source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
, source3
, source4
source5
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,T3,T4,T5,T6,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull SingleSource<? extends T3> source3, @NonNull SingleSource<? extends T4> source4, @NonNull SingleSource<? extends T5> source5, @NonNull SingleSource<? extends T6> source6, @NonNull Function6<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to six items
emitted by six other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeT3
- the third source SingleSource
's value typeT4
- the fourth source SingleSource
's value typeT5
- the fifth source SingleSource
's value typeT6
- the sixth source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
source3
- a third source SingleSource
source4
- a fourth source SingleSource
source5
- a fifth source SingleSource
source6
- a sixth source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
, source3
, source4
source5
, source6
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,T3,T4,T5,T6,T7,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull SingleSource<? extends T3> source3, @NonNull SingleSource<? extends T4> source4, @NonNull SingleSource<? extends T5> source5, @NonNull SingleSource<? extends T6> source6, @NonNull SingleSource<? extends T7> source7, @NonNull Function7<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to seven items
emitted by seven other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeT3
- the third source SingleSource
's value typeT4
- the fourth source SingleSource
's value typeT5
- the fifth source SingleSource
's value typeT6
- the sixth source SingleSource
's value typeT7
- the seventh source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
source3
- a third source SingleSource
source4
- a fourth source SingleSource
source5
- a fifth source SingleSource
source6
- a sixth source SingleSource
source7
- a seventh source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
, source3
, source4
source5
, source6
, source7
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,T3,T4,T5,T6,T7,T8,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull SingleSource<? extends T3> source3, @NonNull SingleSource<? extends T4> source4, @NonNull SingleSource<? extends T5> source5, @NonNull SingleSource<? extends T6> source6, @NonNull SingleSource<? extends T7> source7, @NonNull SingleSource<? extends T8> source8, @NonNull Function8<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to eight items
emitted by eight other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeT3
- the third source SingleSource
's value typeT4
- the fourth source SingleSource
's value typeT5
- the fifth source SingleSource
's value typeT6
- the sixth source SingleSource
's value typeT7
- the seventh source SingleSource
's value typeT8
- the eighth source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
source3
- a third source SingleSource
source4
- a fourth source SingleSource
source5
- a fifth source SingleSource
source6
- a sixth source SingleSource
source7
- a seventh source SingleSource
source8
- an eighth source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
, source3
, source4
source5
, source6
, source7
, source8
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public static <T1,T2,T3,T4,T5,T6,T7,T8,T9,R> @NonNull Single<R> zip(@NonNull SingleSource<? extends T1> source1, @NonNull SingleSource<? extends T2> source2, @NonNull SingleSource<? extends T3> source3, @NonNull SingleSource<? extends T4> source4, @NonNull SingleSource<? extends T5> source5, @NonNull SingleSource<? extends T6> source6, @NonNull SingleSource<? extends T7> source7, @NonNull SingleSource<? extends T8> source8, @NonNull SingleSource<? extends T9> source9, @NonNull Function9<? super T1,? super T2,? super T3,? super T4,? super T5,? super T6,? super T7,? super T8,? super T9,? extends R> zipper)
Single
that emits the results of a specified combiner function applied to nine items
emitted by nine other SingleSource
s.
zip
does not operate by default on a particular Scheduler
.T1
- the first source SingleSource
's value typeT2
- the second source SingleSource
's value typeT3
- the third source SingleSource
's value typeT4
- the fourth source SingleSource
's value typeT5
- the fifth source SingleSource
's value typeT6
- the sixth source SingleSource
's value typeT7
- the seventh source SingleSource
's value typeT8
- the eighth source SingleSource
's value typeT9
- the ninth source SingleSource
's value typeR
- the result value typesource1
- the first source SingleSource
source2
- a second source SingleSource
source3
- a third source SingleSource
source4
- a fourth source SingleSource
source5
- a fifth source SingleSource
source6
- a sixth source SingleSource
source7
- a seventh source SingleSource
source8
- an eighth source SingleSource
source9
- a ninth source SingleSource
zipper
- a function that, when applied to the item emitted by each of the source SingleSource
s, results in an
item that will be emitted by the resulting Single
Single
that emits the zipped resultsNullPointerException
- if source1
, source2
, source3
, source4
source5
, source6
, source7
, source8
,
source9
or zipper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") @SafeVarargs public static <T,R> @NonNull Single<R> zipArray(@NonNull Function<? super Object[],? extends R> zipper, @NonNull SingleSource<? extends T>... sources)
SingleSource
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 a NoSuchElementException
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 an Object[]
instead. Unfortunately, a
Function<Integer[], R>
passed to the method would trigger a ClassCastException
.
If any of the SingleSource
s signal an error, all other SingleSource
s get disposed and the
error emitted to downstream immediately.
zipArray
does not operate by default on a particular Scheduler
.T
- the common value typeR
- the result value typesources
- the array of SingleSource
instances. An empty sequence will result in an
onError
signal of NoSuchElementException
.zipper
- the function that receives an array with values from each SingleSource
and should return a value to be emitted to downstreamSingle
instanceNullPointerException
- if zipper
or sources
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> ambWith(@NonNull SingleSource<? extends T> other)
SingleSource
whichever signals first.
ambWith
does not operate by default on a particular Scheduler
.other
- the other SingleSource
to race for the first emission of success or errorSingle
instance. A subscription to this provided source will occur after subscribing
to the current source.NullPointerException
- if other
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> hide()
Single
, including the Disposable
that is sent
to the downstream via onSubscribe()
.
hide
does not operate by default on a particular Scheduler
.Single
instance@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final <R> @NonNull Single<R> compose(@NonNull SingleTransformer<? super T,? extends R> transformer)
Single
by applying a particular SingleTransformer
function to it.
This method operates on the Single
itself whereas lift(io.reactivex.rxjava3.core.SingleOperator<? extends R, ? super T>)
operates on SingleObserver
s.
If the operator you are creating is designed to act on the individual item emitted by a Single
, use
lift(io.reactivex.rxjava3.core.SingleOperator<? extends R, ? super T>)
. If your operator is designed to transform the current Single
as a whole (for instance, by
applying a particular set of existing RxJava operators to it) use compose
.
compose
does not operate by default on a particular Scheduler
.R
- the value type of the single returned by the transformer functiontransformer
- the transformer function, not null
Single
instanceNullPointerException
- if transformer
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> cache()
Single
and replays it to late SingleObserver
s.
The returned Single
subscribes to the current Single
when the first SingleObserver
subscribes.
cache
does not operate by default on a particular Scheduler
.Single
instance@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U> @NonNull Single<U> cast(@NonNull Class<? extends U> clazz)
Single
into the target type or signals a
ClassCastException
if not compatible.
cast
does not operate by default on a particular Scheduler
.U
- the target typeclazz
- the type token to use for casting the success result from the current Single
Single
instanceNullPointerException
- if clazz
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Single<R> concatMap(@NonNull Function<? super T,? extends SingleSource<? extends R>> mapper)
Single
that is based on applying a specified function to the item emitted by the current Single
,
where that function returns a SingleSource
.
The operator is an alias for flatMap(Function)
concatMap
does not operate by default on a particular Scheduler
.R
- the result value typemapper
- a function that, when applied to the item emitted by the current Single
, returns a SingleSource
Single
returned from mapper
when applied to the item emitted by the current Single
NullPointerException
- if mapper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Completable concatMapCompletable(@NonNull Function<? super T,? extends CompletableSource> mapper)
Completable
that completes based on applying a specified function to the item emitted by the
current Single
, where that function returns a CompletableSource
.
The operator is an alias for flatMapCompletable(Function)
.
concatMapCompletable
does not operate by default on a particular Scheduler
.mapper
- a function that, when applied to the item emitted by the current Single
, returns a
CompletableSource
Completable
instanceNullPointerException
- if mapper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Maybe<R> concatMapMaybe(@NonNull Function<? super T,? extends MaybeSource<? extends R>> mapper)
Maybe
that is based on applying a specified function to the item emitted by the current Single
,
where that function returns a MaybeSource
.
The operator is an alias for flatMapMaybe(Function)
.
concatMapMaybe
does not operate by default on a particular Scheduler
.R
- the result value typemapper
- a function that, when applied to the item emitted by the current Single
, returns a MaybeSource
Maybe
returned from mapper
when applied to the item emitted by the current Single
NullPointerException
- if mapper
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Flowable<T> concatWith(@NonNull SingleSource<? extends T> other)
Flowable
that emits the item emitted by the current Single
, then the item emitted by the
specified SingleSource
.
Flowable
honors the backpressure of the downstream consumer.concatWith
does not operate by default on a particular Scheduler
.other
- a SingleSource
to be concatenated after the currentFlowable
that emits the item emitted by the current Single
, followed by the item emitted by
other
NullPointerException
- if other
is null
@CheckReturnValue @SchedulerSupport(value="io.reactivex:computation") @NonNull public final @NonNull Single<T> delay(long time, @NonNull TimeUnit unit)
Single
by the specified amount.
An error signal will not be delayed.
delay
operates by default on the computation
Scheduler
.time
- the amount of time the success signal should be delayed forunit
- the time unitSingle
instanceNullPointerException
- if unit
is null
delay(long, TimeUnit, boolean)
@CheckReturnValue @SchedulerSupport(value="io.reactivex:computation") @NonNull public final @NonNull Single<T> delay(long time, @NonNull TimeUnit unit, boolean delayError)
Single
by the specified amount.
delay
operates by default on the computation
Scheduler
.History: 2.1.5 - experimental
time
- the amount of time the success or error signal should be delayed forunit
- the time unitdelayError
- if true
, both success and error signals are delayed. if false
, only success signals are delayed.Single
instanceNullPointerException
- if unit
is null
@CheckReturnValue @SchedulerSupport(value="custom") @NonNull public final @NonNull Single<T> delay(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler)
Single
by the specified amount.
An error signal will not be delayed.
Scheduler
where the non-blocking wait and emission happenstime
- 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 emissionSingle
instanceNullPointerException
- if unit
is null
, or
if scheduler
is null
delay(long, TimeUnit, Scheduler, boolean)
@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<T> delay(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, boolean delayError)
Single
by the specified amount.
Scheduler
where the non-blocking wait and emission happensHistory: 2.1.5 - experimental
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
- if true
, both success and error signals are delayed. if false
, only success signals are delayed.Single
instanceNullPointerException
- if unit
is null
, or
if scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> delaySubscription(@NonNull CompletableSource subscriptionIndicator)
Single
until the given other CompletableSource
completes.
If the delaying source signals an error, that error is re-emitted and no subscription
to the current Single
happens.
delaySubscription
does not operate by default on a particular Scheduler
.subscriptionIndicator
- the CompletableSource
that has to complete before the subscription to the
current Single
happensSingle
instanceNullPointerException
- if subscriptionIndicator
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U> @NonNull Single<T> delaySubscription(@NonNull SingleSource<U> subscriptionIndicator)
Single
until the given other SingleSource
signals success.
If the delaying source signals an error, that error is re-emitted and no subscription
to the current Single
happens.
delaySubscription
does not operate by default on a particular Scheduler
.U
- the element type of the other sourcesubscriptionIndicator
- the SingleSource
that has to complete before the subscription to the
current Single
happensSingle
instanceNullPointerException
- if subscriptionIndicator
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U> @NonNull Single<T> delaySubscription(@NonNull ObservableSource<U> subscriptionIndicator)
Single
until the given other ObservableSource
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.
delaySubscription
does not operate by default on a particular Scheduler
.U
- the element type of the other sourcesubscriptionIndicator
- the ObservableSource
that has to signal a value or complete before the
subscription to the current Single
happensSingle
instanceNullPointerException
- if subscriptionIndicator
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U> @NonNull Single<T> delaySubscription(@NonNull Publisher<U> subscriptionIndicator)
Single
until the given other Publisher
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).
other
publisher is consumed in an unbounded fashion but will be
cancelled after the first item it produced.delaySubscription
does not operate by default on a particular Scheduler
.U
- the element type of the other sourcesubscriptionIndicator
- the Publisher
that has to signal a value or complete before the
subscription to the current Single
happensSingle
instanceNullPointerException
- if subscriptionIndicator
is null
@CheckReturnValue @SchedulerSupport(value="io.reactivex:computation") @NonNull public final @NonNull Single<T> delaySubscription(long time, @NonNull TimeUnit unit)
Single
until the given time delay elapsed.
delaySubscription
does by default subscribe to the current Single
on the computation
Scheduler
after the delay.time
- the time amount to wait with the subscriptionunit
- the time unit of the waitingSingle
instanceNullPointerException
- if unit
is null
@CheckReturnValue @SchedulerSupport(value="custom") @NonNull public final @NonNull Single<T> delaySubscription(long time, @NonNull TimeUnit unit, @NonNull Scheduler scheduler)
Single
until the given time delay elapsed.
delaySubscription
does by default subscribe to the current Single
on the Scheduler
you provided, after the delay.time
- the time amount to wait with the subscriptionunit
- the time unit of the waitingscheduler
- the Scheduler
to wait on and subscribe on to the current Single
Single
instanceNullPointerException
- if unit
or scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Maybe<R> dematerialize(@NonNull Function<? super T,Notification<R>> selector)
Notification
success value of the current Single
back into normal
onSuccess
, onError
or onComplete
signals as a
Maybe
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 type
Notification<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.
dematerialize
does not operate by default on a particular Scheduler
.Example:
Single.just(Notification.createOnNext(1))
.dematerialize(notification -> notification)
.test()
.assertResult(1);
History: 2.2.4 - experimental
R
- the result typeselector
- the function called with the success item and should
return a Notification
instance.Maybe
instanceNullPointerException
- if selector
is null
materialize()
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doAfterSuccess(@NonNull Consumer<? super T> onAfterSuccess)
Note that the doAfterSuccess
action is shared between subscriptions and as such
should be thread-safe.
doAfterSuccess
does not operate by default on a particular Scheduler
.History: 2.0.1 - experimental
onAfterSuccess
- the Consumer
that will be called after emitting an item from upstream to the downstreamSingle
instanceNullPointerException
- if onAfterSuccess
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doAfterTerminate(@NonNull Action onAfterTerminate)
Action
to be called after this Single
invokes either onSuccess
or onError
.
Note that the doAfterTerminate
action is shared between subscriptions and as such
should be thread-safe.
doAfterTerminate
does not operate by default on a particular Scheduler
.History: 2.0.6 - experimental
onAfterTerminate
- an Action
to be invoked when the current Single
finishesSingle
that emits the same items as the current Single
, then invokes the
Action
NullPointerException
- if onAfterTerminate
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doFinally(@NonNull Action onFinally)
Single
signals onSuccess
or onError
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.
doFinally
does not operate by default on a particular Scheduler
.History: 2.0.1 - experimental
onFinally
- the action called when this Single
terminates or gets disposedSingle
instanceNullPointerException
- if onFinally
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> doOnLifecycle(@NonNull Consumer<? super Disposable> onSubscribe, @NonNull Action onDispose)
onXXX
method (shared between all SingleObserver
s) for the lifecycle events of
the sequence (subscription, disposal).
doOnLifecycle
does not operate by default on a particular Scheduler
.onSubscribe
- a Consumer
called with the Disposable
sent via SingleObserver.onSubscribe(Disposable)
onDispose
- called when the downstream disposes the Disposable
via dispose()
Single
instanceNullPointerException
- if onSubscribe
or onDispose
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doOnSubscribe(@NonNull Consumer<? super Disposable> onSubscribe)
Disposable
sent through the onSubscribe
for each
SingleObserver
that subscribes to the current Single
.
doOnSubscribe
does not operate by default on a particular Scheduler
.onSubscribe
- the consumer called with the Disposable
sent via onSubscribe
Single
instanceNullPointerException
- if onSubscribe
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doOnTerminate(@NonNull Action onTerminate)
Single
instance that calls the given onTerminate
callback
just before this Single
completes normally or with an exception.
This differs from doAfterTerminate
in that this happens before the onSuccess
or
onError
notification.
doOnTerminate
does not operate by default on a particular Scheduler
.History: 2.2.7 - experimental
onTerminate
- the action to invoke when the consumer calls onSuccess
or onError
Single
instanceNullPointerException
- if onTerminate
is null
doOnTerminate(Action)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doOnSuccess(@NonNull Consumer<? super T> onSuccess)
onSuccess
for each
SingleObserver
that subscribes to the current Single
.
doOnSuccess
does not operate by default on a particular Scheduler
.onSuccess
- the consumer called with the success value of onSuccess
Single
instanceNullPointerException
- if onSuccess
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doOnEvent(@NonNull BiConsumer<? super T,? super Throwable> onEvent)
onError
or the value
via onSuccess
for each SingleObserver
that subscribes to the current Single
.
doOnEvent
does not operate by default on a particular Scheduler
.onEvent
- the consumer called with the success value of onEventSingle
instanceNullPointerException
- if onEvent
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doOnError(@NonNull Consumer<? super Throwable> onError)
onError
for each
SingleObserver
that subscribes to the current Single
.
doOnError
does not operate by default on a particular Scheduler
.onError
- the consumer called with the success value of onError
Single
instanceNullPointerException
- if onError
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> doOnDispose(@NonNull Action onDispose)
Action
if a SingleObserver
subscribed to the current Single
disposes the common Disposable
it received via onSubscribe
.
doOnDispose
does not operate by default on a particular Scheduler
.onDispose
- the action called when the subscription is disposedSingle
instanceNullPointerException
- if onDispose
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Maybe<T> filter(@NonNull Predicate<? super T> predicate)
Single
via a predicate function and emitting it if the predicate
returns true
, completing otherwise.
filter
does not operate by default on a particular Scheduler
.predicate
- a function that evaluates the item emitted by the current Single
, returning true
if it passes the filterMaybe
that emit the item emitted by the current Single
that the filter
evaluates as true
NullPointerException
- if predicate
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Single<R> flatMap(@NonNull Function<? super T,? extends SingleSource<? extends R>> mapper)
Single
that is based on applying a specified function to the item emitted by the current Single
,
where that function returns a SingleSource
.
flatMap
does not operate by default on a particular Scheduler
.R
- the result value typemapper
- a function that, when applied to the item emitted by the current Single
, returns a SingleSource
Single
returned from mapper
when applied to the item emitted by the current Single
NullPointerException
- if mapper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U,R> @NonNull Single<R> flatMap(@NonNull Function<? super T,? extends SingleSource<? extends U>> mapper, @NonNull BiFunction<? super T,? super U,? extends R> combiner)
Single
that emits the results of a specified function to the pair of values emitted by the
current Single
and a specified mapped SingleSource
.
flatMap
does not operate by default on a particular Scheduler
.U
- the type of items emitted by the SingleSource
returned by the mapper
functionR
- the type of items emitted by the resulting Single
mapper
- a function that returns a SingleSource
for the item emitted by the current Single
combiner
- a function that combines one item emitted by each of the source and collection SingleSource
and
returns an item to be emitted by the resulting SingleSource
Single
instanceNullPointerException
- if mapper
or combiner
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Single<R> flatMap(@NonNull Function<? super T,? extends SingleSource<? extends R>> onSuccessMapper, @NonNull Function<? super Throwable,? extends SingleSource<? extends R>> onErrorMapper)
onSuccess
or onError
signals of the current Single
into a SingleSource
and emits that
SingleSource
's signals.
flatMap
does not operate by default on a particular Scheduler
.R
- the result typeonSuccessMapper
- a function that returns a SingleSource
to merge for the onSuccess
item emitted by this Single
onErrorMapper
- a function that returns a SingleSource
to merge for an onError
notification from this Single
Single
instanceNullPointerException
- if onSuccessMapper
or onErrorMapper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Maybe<R> flatMapMaybe(@NonNull Function<? super T,? extends MaybeSource<? extends R>> mapper)
Maybe
that is based on applying a specified function to the item emitted by the current Single
,
where that function returns a MaybeSource
.
flatMapMaybe
does not operate by default on a particular Scheduler
.R
- the result value typemapper
- a function that, when applied to the item emitted by the current Single
, returns a MaybeSource
Maybe
returned from mapper
when applied to the item emitted by the current Single
NullPointerException
- if mapper
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Flowable<R> flatMapPublisher(@NonNull Function<? super T,? extends Publisher<? extends R>> mapper)
Flowable
that emits items based on applying a specified function to the item emitted by the
current Single
, where that function returns a Publisher
.
Flowable
honors the backpressure of the downstream consumer
and the Publisher
returned by the mapper function is expected to honor it as well.flatMapPublisher
does not operate by default on a particular Scheduler
.R
- the result value typemapper
- a function that, when applied to the item emitted by the current Single
, returns a
Publisher
Flowable
instanceNullPointerException
- if mapper
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U> @NonNull Flowable<U> flattenAsFlowable(@NonNull Function<? super T,? extends Iterable<? extends U>> mapper)
Single
into an Iterable
and emits its items as a
Flowable
sequence.
flattenAsFlowable
does not operate by default on a particular Scheduler
.U
- the type of item emitted by the resulting Iterable
mapper
- a function that returns an Iterable
sequence of values for when given an item emitted by the
current Single
Flowable
instanceNullPointerException
- if mapper
is null
flattenStreamAsFlowable(Function)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U> @NonNull Observable<U> flattenAsObservable(@NonNull Function<? super T,? extends Iterable<? extends U>> mapper)
Single
into an Iterable
and emits its items as an
Observable
sequence.
flattenAsObservable
does not operate by default on a particular Scheduler
.U
- the type of item emitted by the resulting Iterable
mapper
- a function that returns an Iterable
sequence of values for when given an item emitted by the
current Single
Observable
instanceNullPointerException
- if mapper
is null
flattenStreamAsObservable(Function)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Observable<R> flatMapObservable(@NonNull Function<? super T,? extends ObservableSource<? extends R>> mapper)
Observable
that is based on applying a specified function to the item emitted by the current Single
,
where that function returns an ObservableSource
.
flatMapObservable
does not operate by default on a particular Scheduler
.R
- the result value typemapper
- a function that, when applied to the item emitted by the current Single
, returns an ObservableSource
Observable
instanceNullPointerException
- if mapper
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Completable flatMapCompletable(@NonNull Function<? super T,? extends CompletableSource> mapper)
Completable
that completes based on applying a specified function to the item emitted by the
current Single
, where that function returns a CompletableSource
.
flatMapCompletable
does not operate by default on a particular Scheduler
.mapper
- a function that, when applied to the item emitted by the current Single
, returns a
CompletableSource
Completable
instanceNullPointerException
- if mapper
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final T blockingGet()
Single
signals a success value (which is returned) or
an exception (which is propagated).
blockingGet
does not operate by default on a particular Scheduler
.Exception
into RuntimeException
and throws that. Otherwise, RuntimeException
s and
Error
s are rethrown as they are.@SchedulerSupport(value="none") public final void blockingSubscribe()
Single
and blocks the current thread until it terminates.
blockingSubscribe
does not operate by default on a particular Scheduler
.Single
signals an error,
the Throwable
is routed to the global error handler via RxJavaPlugins.onError(Throwable)
.
If the current thread is interrupted, an InterruptedException
is routed to the same global error handler.
blockingSubscribe(Consumer)
,
blockingSubscribe(Consumer, Consumer)
@SchedulerSupport(value="none") public final void blockingSubscribe(@NonNull Consumer<? super T> onSuccess)
Single
and calls given onSuccess
callback on the current thread
when it completes normally.
blockingSubscribe
does not operate by default on a particular Scheduler
.Single
signals an error or onSuccess
throws,
the respective Throwable
is routed to the global error handler via RxJavaPlugins.onError(Throwable)
.
If the current thread is interrupted, an InterruptedException
is routed to the same global error handler.
onSuccess
- the Consumer
to call if the current Single
succeedsNullPointerException
- if onSuccess
is null
blockingSubscribe(Consumer, Consumer)
@SchedulerSupport(value="none") public final void blockingSubscribe(@NonNull Consumer<? super T> onSuccess, @NonNull Consumer<? super Throwable> onError)
Single
and calls the appropriate callback on the current thread
when it terminates.
blockingSubscribe
does not operate by default on a particular Scheduler
.onSuccess
or onError
throw, the Throwable
is routed to the
global error handler via RxJavaPlugins.onError(Throwable)
.
If the current thread is interrupted, the onError
consumer is called with an InterruptedException
.
onSuccess
- the Consumer
to call if the current Single
succeedsonError
- the Consumer
to call if the current Single
signals an errorNullPointerException
- if onSuccess
or onError
is null
@SchedulerSupport(value="none") public final void blockingSubscribe(@NonNull SingleObserver<? super T> observer)
Single
and calls the appropriate SingleObserver
method on the current thread.
blockingSubscribe
does not operate by default on a particular Scheduler
.onError
signal is delivered to the SingleObserver.onError(Throwable)
method.
If any of the SingleObserver
's methods throw, the RuntimeException
is propagated to the caller of this method.
If the current thread is interrupted, an InterruptedException
is delivered to observer.onError
.
observer
- the SingleObserver
to call methods on the current threadNullPointerException
- if observer
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Single<R> lift(@NonNull SingleOperator<? extends R,? super T> lift)
Single
which, when subscribed to, invokes the apply(SingleObserver)
method
of the provided SingleOperator
for each individual downstream Single
and allows the
insertion of a custom operator by accessing the downstream's SingleObserver
during this subscription phase
and providing a new SingleObserver
, 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's SingleObserver
and forwards the
onSuccess
and onError
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 of dispose
and isDisposed
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 abstract Single
class and creating a SingleTransformer
with it is recommended.
Note also that it is not possible to stop the subscription phase in lift()
as the apply()
method
requires a non-null
SingleObserver
instance to be returned, which is then unconditionally subscribed to
the current Single
. 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 a SingleObserver
that should immediately dispose the upstream's Disposable
in its
onSubscribe
method. Again, using a SingleTransformer
and extending the Single
is
a better option as subscribeActual(io.reactivex.rxjava3.core.SingleObserver<? super T>)
can decide to not subscribe to its upstream after all.
lift
does not operate by default on a particular Scheduler
, however, the
SingleOperator
may use a Scheduler
to support its own asynchronous behavior.R
- the output value typelift
- the SingleOperator
that receives the downstream's SingleObserver
and should return
a SingleObserver
with custom behavior to be used as the consumer for the current
Single
.Single
instanceNullPointerException
- if lift
is null
compose(SingleTransformer)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <R> @NonNull Single<R> map(@NonNull Function<? super T,? extends R> mapper)
Single
that applies a specified function to the item emitted by the current Single
and
emits the result of this function application.
map
does not operate by default on a particular Scheduler
.R
- the result value typemapper
- a function to apply to the item emitted by the Single
Single
that emits the item from the current Single
, transformed by the specified functionNullPointerException
- if mapper
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<Notification<T>> materialize()
Single
into a Notification
of the same kind
and emits it as a single success value to downstream.
materialize
does not operate by default on a particular Scheduler
.History: 2.2.4 - experimental
Single
instancedematerialize(Function)
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<Boolean> contains(@NonNull Object item)
true
if the current Single
signals a success value that is Object.equals(Object)
with the value
provided.
contains
does not operate by default on a particular Scheduler
.item
- the value to compare against the success value of this Single
Single
instanceNullPointerException
- if item
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<Boolean> contains(@NonNull Object item, @NonNull BiPredicate<Object,Object> comparer)
true
if the current Single
signals a success value that is equal with
the value provided by calling a BiPredicate
.
contains
does not operate by default on a particular Scheduler
.item
- the value to compare against the success value of this Single
comparer
- the function that receives the success value of this Single
, the value provided
and should return true
if they are considered equalSingle
instanceNullPointerException
- if item
or comparer
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Flowable<T> mergeWith(@NonNull SingleSource<? extends T> other)
Single
and another SingleSource
into one Flowable
, without any transformation.
You can combine items emitted by multiple SingleSource
s so that they appear as one Flowable
, by using
the mergeWith
method.
Flowable
honors the backpressure of the downstream consumer.mergeWith
does not operate by default on a particular Scheduler
.other
- a SingleSource
to be mergedFlowable
instanceNullPointerException
- if other
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <U> @NonNull Maybe<U> ofType(@NonNull Class<U> clazz)
Single
, only emitting its success value if that
is an instance of the supplied Class
.
ofType
does not operate by default on a particular Scheduler
.U
- the output typeclazz
- the class type to filter the items emitted by the current Single
Maybe
instanceNullPointerException
- if clazz
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<T> observeOn(@NonNull Scheduler scheduler)
Single
on the specified Scheduler
,
asynchronously.
Scheduler
this operator will use.scheduler
- the Scheduler
to notify subscribers onSingle
instanceNullPointerException
- if scheduler
is null
subscribeOn(io.reactivex.rxjava3.core.Scheduler)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> onErrorReturn(@NonNull Function<Throwable,? extends T> itemSupplier)
Throwable
error signaled by the current
Single
instead of signaling the error via onError
.
By default, when a Single
encounters an error that prevents it from emitting the expected item to its
subscriber, the Single
invokes its subscriber's SingleObserver.onError(java.lang.Throwable)
method, and then quits
without invoking any more of its observer's methods. The onErrorReturn
method changes this
behavior. If you pass a function (resumeFunction
) to a Single
's onErrorReturn
method, if
the original Single
encounters an error, instead of invoking its observer's
SingleObserver.onError(java.lang.Throwable)
method, it will instead emit the return value of resumeFunction
.
You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.
onErrorReturn
does not operate by default on a particular Scheduler
.itemSupplier
- a function that returns an item that the new Single
will emit if the current Single
encounters
an errorSingle
instanceNullPointerException
- if itemSupplier
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> onErrorReturnItem(@NonNull T item)
Single
signals an error.
onErrorReturnItem
does not operate by default on a particular Scheduler
.item
- the value to signal if the current Single
failsSingle
instanceNullPointerException
- if item
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> onErrorResumeWith(@NonNull SingleSource<? extends T> fallback)
SingleSource
when the current Single
fails instead of
signaling the error via onError
.
By default, when a Single
encounters an error that prevents it from emitting the expected item to
its SingleObserver
, the Single
invokes its SingleObserver
's onError
method, and then quits
without invoking any more of its SingleObserver
's methods. The onErrorResumeWith
method changes this
behavior. If you pass another Single
(resumeSingleInCaseOfError
) to a Single
's
onErrorResumeWith
method, if the original Single
encounters an error, instead of invoking its
SingleObserver
's onError
method, it will instead relinquish control to resumeSingleInCaseOfError
which
will invoke the SingleObserver
's onSuccess
method if it is able to do so. In such a case,
because no Single
necessarily invokes onError
, the SingleObserver
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.
onErrorResumeWith
does not operate by default on a particular Scheduler
.fallback
- a Single
that will take control if source Single
encounters an error.Single
instanceNullPointerException
- if fallback
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Maybe<T> onErrorComplete()
Maybe
instance that if the current Single
emits an error, it will emit an onComplete
and swallow the throwable.
onErrorComplete
does not operate by default on a particular Scheduler
.Maybe
instance@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Maybe<T> onErrorComplete(@NonNull Predicate<? super Throwable> predicate)
Maybe
instance that if this Single
emits an error and the predicate returns
true
, it will emit an onComplete
and swallow the throwable.
onErrorComplete
does not operate by default on a particular Scheduler
.predicate
- the predicate to call when an Throwable
is emitted which should return true
if the Throwable
should be swallowed and replaced with an onComplete
.Maybe
instanceNullPointerException
- if predicate
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> onErrorResumeNext(@NonNull Function<? super Throwable,? extends SingleSource<? extends T>> fallbackSupplier)
SingleSource
returned for the failure Throwable
of the current Single
by a
function instead of signaling the error via onError
.
By default, when a Single
encounters an error that prevents it from emitting the expected item to
its SingleObserver
, the Single
invokes its SingleObserver
's onError
method, and then quits
without invoking any more of its SingleObserver
's methods. The onErrorResumeNext
method changes this
behavior. If you pass a function that will return another Single
(resumeFunctionInCaseOfError
) to a Single
's
onErrorResumeNext
method, if the original Single
encounters an error, instead of invoking its
SingleObserver
's onError
method, it will instead relinquish control to resumeSingleInCaseOfError
which
will invoke the SingleObserver
's onSuccess
method if it is able to do so. In such a case,
because no Single
necessarily invokes onError
, the SingleObserver
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.
onErrorResumeNext
does not operate by default on a particular Scheduler
.fallbackSupplier
- a function that returns a SingleSource
that will take control if source Single
encounters an error.Single
instanceNullPointerException
- if fallbackSupplier
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> onTerminateDetach()
SingleObserver
if
the sequence is terminated or downstream calls dispose()
.
onTerminateDetach
does not operate by default on a particular Scheduler
.History: 2.1.5 - experimental
Single
which null
s out references to the upstream producer and downstream SingleObserver
if
the sequence is terminated or downstream calls dispose()
@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Flowable<T> repeat()
Single
and emits each success value as a Flowable
sequence.
Flowable
honors the backpressure of the downstream consumer.repeat
does not operate by default on a particular Scheduler
.Flowable
instance@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Flowable<T> repeat(long times)
Single
at most the given number of times and emits each success value as a Flowable
sequence.
Flowable
honors the backpressure of the downstream consumer.repeat
does not operate by default on a particular Scheduler
.times
- the number of times to re-subscribe to the current Single
Flowable
instanceIllegalArgumentException
- if times
is negative@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Flowable<T> repeatWhen(@NonNull Function<? super Flowable<Object>,? extends Publisher<?>> handler)
Single
if
the Publisher
returned by the handler function signals a value in response to a
value signaled through the Flowable
the handler receives.
Flowable
honors the backpressure of the downstream consumer.
The Publisher
returned by the handler function is expected to honor backpressure as well.repeatWhen
does not operate by default on a particular Scheduler
.handler
- the function that is called with a Flowable
that signals a value when the Single
signaled a success value and returns a Publisher
that has to signal a value to
trigger a resubscription to the current Single
, otherwise the terminal signal of
the Publisher
will be the terminal signal of the sequence as well.Flowable
instanceNullPointerException
- if handler
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Flowable<T> repeatUntil(@NonNull BooleanSupplier stop)
Single
until the given BooleanSupplier
returns true
and emits the success items as a Flowable
sequence.
Flowable
honors the backpressure of the downstream consumer.repeatUntil
does not operate by default on a particular Scheduler
.stop
- the BooleanSupplier
called after the current Single
succeeds and if returns false
,
the Single
is re-subscribed; otherwise the sequence completes.Flowable
instanceNullPointerException
- if stop
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> retry()
Single
indefinitely if it fails with an onError
.
retry
does not operate by default on a particular Scheduler
.Single
instance@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> retry(long times)
Single
if it fails with an onError
.
retry
does not operate by default on a particular Scheduler
.times
- the number of times to resubscribe if the current Single
failsSingle
instanceIllegalArgumentException
- if times
is negative@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> retry(@NonNull BiPredicate<? super Integer,? super Throwable> predicate)
Single
if the given predicate returns true
when the Single
fails
with an onError
.
retry
does not operate by default on a particular Scheduler
.predicate
- the predicate called with the resubscription count and the failure Throwable
and should return true
if a resubscription should happenSingle
instanceNullPointerException
- if predicate
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> retry(long times, @NonNull Predicate<? super Throwable> predicate)
false
, whichever happens first
if it fails with an onError
.
retry
does not operate by default on a particular Scheduler
.History: 2.1.8 - experimental
times
- the number of times to resubscribe if the current Single
failspredicate
- the predicate called with the failure Throwable
and should return true
if a resubscription should happenSingle
instanceNullPointerException
- if predicate
is null
IllegalArgumentException
- if times
is negative@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> retry(@NonNull Predicate<? super Throwable> predicate)
Single
if the given predicate returns true
when the Single
fails
with an onError
.
retry
does not operate by default on a particular Scheduler
.predicate
- the predicate called with the failure Throwable
and should return true
if a resubscription should happenSingle
instanceNullPointerException
- if predicate
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> retryUntil(@NonNull BooleanSupplier stop)
true
.
retryUntil
does not operate by default on a particular Scheduler
.stop
- the function that should return true
to stop retryingSingle
instanceNullPointerException
- if stop
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Single<T> retryWhen(@NonNull Function<? super Flowable<Throwable>,? extends Publisher<?>> handler)
Single
if and when the Publisher
returned by the handler
function signals a value.
If the Publisher
signals an onComplete
, the resulting Single
will signal a NoSuchElementException
.
Note that the inner Publisher
returned by the handler function should signal
either onNext
, onError
or onComplete
in response to the received
Throwable
to indicate the operator should retry or terminate. If the upstream to
the operator is asynchronous, signaling onNext
followed by onComplete
immediately may
result in the sequence to be completed immediately. Similarly, if this inner
Publisher
signals onError
or onComplete
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();
retryWhen
does not operate by default on a particular Scheduler
.handler
- the function that receives a Flowable
of the error the Single
emits and should
return a Publisher
that should signal a normal value (in response to the
throwable the Flowable
emits) to trigger a resubscription or signal an error to
be the output of the resulting Single
Single
instanceNullPointerException
- if handler
is null
@SchedulerSupport(value="none") public final void safeSubscribe(@NonNull SingleObserver<? super T> observer)
SingleObserver
, catches any RuntimeException
s thrown by its
SingleObserver.onSubscribe(Disposable)
, SingleObserver.onSuccess(Object)
or
SingleObserver.onError(Throwable)
methods* and routes those to the global error handler
via RxJavaPlugins.onError(Throwable)
.
By default, the Single
protocol forbids the onXXX
methods to throw, but some
SingleObserver
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.
safeSubscribe
does not operate by default on a particular Scheduler
.observer
- the potentially misbehaving SingleObserver
NullPointerException
- if observer
is null
subscribe(Consumer,Consumer)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") @BackpressureSupport(value=FULL) public final @NonNull Flowable<T> startWith(@NonNull CompletableSource other)
Flowable
which first runs the other CompletableSource
then the current Single
if the other completed normally.
Flowable
honors the backpressure of the downstream consumer.startWith
does not operate by default on a particular Scheduler
.other
- the other CompletableSource
to run firstFlowable
instanceNullPointerException
- if other
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") @BackpressureSupport(value=FULL) public final @NonNull Flowable<T> startWith(@NonNull SingleSource<T> other)
Flowable
which first runs the other SingleSource
then the current Single
if the other succeeded normally.
Flowable
honors the backpressure of the downstream consumer.startWith
does not operate by default on a particular Scheduler
.other
- the other SingleSource
to run firstFlowable
instanceNullPointerException
- if other
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") @BackpressureSupport(value=FULL) public final @NonNull Flowable<T> startWith(@NonNull MaybeSource<T> other)
Flowable
which first runs the other MaybeSource
then the current Single
if the other succeeded or completed normally.
Flowable
honors the backpressure of the downstream consumer.startWith
does not operate by default on a particular Scheduler
.other
- the other MaybeSource
to run firstFlowable
instanceNullPointerException
- if other
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Observable<T> startWith(@NonNull ObservableSource<T> other)
Observable
which first delivers the events
of the other ObservableSource
then runs the current Single
.
startWith
does not operate by default on a particular Scheduler
.other
- the other ObservableSource
to run firstObservable
instanceNullPointerException
- if other
is null
@CheckReturnValue @NonNull @BackpressureSupport(value=FULL) @SchedulerSupport(value="none") public final @NonNull Flowable<T> startWith(@NonNull Publisher<T> other)
Flowable
which first delivers the events
of the other Publisher
then runs the current Single
.
Flowable
honors the backpressure of the downstream consumer
and expects the other Publisher
to honor it as well.startWith
does not operate by default on a particular Scheduler
.other
- the other Publisher
to run firstFlowable
instanceNullPointerException
- if other
is null
@SchedulerSupport(value="none") @NonNull public final @NonNull Disposable subscribe()
Single
but ignore its emission or notification.
If the Single
emits an error, it is wrapped into an
OnErrorNotImplementedException
and routed to the RxJavaPlugins.onError(Throwable)
handler.
subscribe
does not operate by default on a particular Scheduler
.Disposable
instance that can be used for disposing the subscription at any timesubscribe(Consumer, Consumer, DisposableContainer)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Disposable subscribe(@NonNull BiConsumer<? super T,? super Throwable> onCallback)
Single
and provides a composite callback to handle the item it emits
or any error notification it issues.
subscribe
does not operate by default on a particular Scheduler
.onCallback
- the callback that receives either the success value or the failure Throwable
(whichever is not null
)Disposable
instance that can be used for disposing the subscription at any timeNullPointerException
- if onCallback
is null
subscribe(Consumer, Consumer, DisposableContainer)
,
ReactiveX operators documentation: Subscribe@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Disposable subscribe(@NonNull Consumer<? super T> onSuccess)
Single
and provides a callback to handle the item it emits.
If the Single
emits an error, it is wrapped into an
OnErrorNotImplementedException
and routed to the RxJavaPlugins.onError(Throwable)
handler.
subscribe
does not operate by default on a particular Scheduler
.onSuccess
- the Consumer<T>
you have designed to accept the emission from the Single
Disposable
instance that can be used for disposing the subscription at any timeNullPointerException
- if onSuccess
is null
subscribe(Consumer, Consumer, DisposableContainer)
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Disposable subscribe(@NonNull Consumer<? super T> onSuccess, @NonNull Consumer<? super Throwable> onError)
Single
and provides callbacks to handle the item it emits or any error notification it
issues.
subscribe
does not operate by default on a particular Scheduler
.onSuccess
- the Consumer<T>
you have designed to accept the emission from the Single
onError
- the Consumer<Throwable>
you have designed to accept any error notification from the
Single
Disposable
instance that can be used for disposing the subscription at any timeNullPointerException
- if onSuccess
or onError
is null
subscribe(Consumer, Consumer, DisposableContainer)
@SchedulerSupport(value="none") @NonNull public final @NonNull Disposable subscribe(@NonNull Consumer<? super T> onSuccess, @NonNull Consumer<? super Throwable> onError, @NonNull DisposableContainer container)
Disposable
SingleObserver
,
adds it to the given DisposableContainer
and ensures, that if the upstream
terminates or this particular Disposable
is disposed, the SingleObserver
is removed
from the given container.
The SingleObserver
will be removed after the callback for the terminal event has been invoked.
subscribe
does not operate by default on a particular Scheduler
.onSuccess
- the callback for upstream itemsonError
- the callback for an upstream error if anycontainer
- the DisposableContainer
(such as CompositeDisposable
) to add and remove the
created Disposable
SingleObserver
Disposable
that allows disposing the particular subscription.NullPointerException
- if onSuccess
, onError
or container
is null
@SchedulerSupport(value="none") public final void subscribe(@NonNull SingleObserver<? super T> observer)
SingleSource
SingleObserver
to this SingleSource
instance.subscribe
in interface SingleSource<T>
observer
- the SingleObserver
, not null
protected abstract void subscribeActual(@NonNull SingleObserver<? super T> observer)
SingleObserver
s.
There is no need to call any of the plugin hooks on the current Single
instance or
the SingleObserver
; all hooks and basic safeguards have been
applied by subscribe(SingleObserver)
before this method gets called.
observer
- the SingleObserver
to handle, not null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final <E extends SingleObserver<? super T>> E subscribeWith(E observer)
SingleObserver
(subclass) to this Single
and returns the given
SingleObserver
as is.
Usage example:
Single<Integer> source = Single.just(1);
CompositeDisposable composite = new CompositeDisposable();
DisposableSingleObserver<Integer> ds = new DisposableSingleObserver<>() {
// ...
};
composite.add(source.subscribeWith(ds));
subscribeWith
does not operate by default on a particular Scheduler
.E
- the type of the SingleObserver
to use and returnobserver
- the SingleObserver
(subclass) to use and return, not null
observer
NullPointerException
- if observer
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<T> subscribeOn(@NonNull Scheduler scheduler)
SingleObserver
s to this Single
on the specified Scheduler
.
Scheduler
this operator will use.scheduler
- the Scheduler
to perform subscription actions onSingle
instanceNullPointerException
- if scheduler
is null
observeOn(io.reactivex.rxjava3.core.Scheduler)
@CheckReturnValue @NonNull @SchedulerSupport(value="io.reactivex:computation") public final @NonNull Single<Timed<T>> timeInterval()
Single
and signals it as a tuple (Timed
)
success value.
If the current Single
fails, the resulting Single
will
pass along the signal to the downstream. To measure the time to error,
use materialize()
and apply timeInterval()
.
timeInterval
uses the computation
Scheduler
for determining the current time upon subscription and upon receiving the
success item from the current Single
.Single
instance@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<Timed<T>> timeInterval(@NonNull Scheduler scheduler)
Single
and signals it as a tuple (Timed
)
success value.
If the current Single
fails, the resulting Single
will
pass along the signal to the downstream. To measure the time to error,
use materialize()
and apply timeInterval(Scheduler)
.
timeInterval
uses the provided Scheduler
for determining the current time upon subscription and upon receiving the
success item from the current Single
.scheduler
- the Scheduler
used for providing the current timeSingle
instanceNullPointerException
- if scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="io.reactivex:computation") public final @NonNull Single<Timed<T>> timeInterval(@NonNull TimeUnit unit)
Single
and signals it as a tuple (Timed
)
success value.
If the current Single
fails, the resulting Single
will
pass along the signals to the downstream. To measure the time to error,
use materialize()
and apply timeInterval(TimeUnit, Scheduler)
.
timeInterval
uses the computation
Scheduler
for determining the current time upon subscription and upon receiving the
success item from the current Single
.unit
- the time unit for measurementSingle
instanceNullPointerException
- if unit
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<Timed<T>> timeInterval(@NonNull TimeUnit unit, @NonNull Scheduler scheduler)
Single
and signals it as a tuple (Timed
)
success value.
If the current Single
is empty or fails, the resulting Single
will
pass along the signals to the downstream. To measure the time to termination,
use materialize()
and apply timeInterval(TimeUnit, Scheduler)
.
timeInterval
uses the provided Scheduler
for determining the current time upon subscription and upon receiving the
success item from the current Single
.unit
- the time unit for measurementscheduler
- the Scheduler
used for providing the current timeSingle
instanceNullPointerException
- if unit
or scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="io.reactivex:computation") public final @NonNull Single<Timed<T>> timestamp()
Single
with the current time (in milliseconds) of
its reception, using the computation
Scheduler
as time source,
then signals them as a Timed
instance.
If the current Single
is empty or fails, the resulting Single
will
pass along the signals to the downstream. To get the timestamp of the error,
use materialize()
and apply timestamp()
.
timestamp
uses the computation
Scheduler
for determining the current time upon receiving the
success item from the current Single
.Single
instance@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<Timed<T>> timestamp(@NonNull Scheduler scheduler)
Single
with the current time (in milliseconds) of
its reception, using the given Scheduler
as time source,
then signals them as a Timed
instance.
If the current Single
is empty or fails, the resulting Single
will
pass along the signals to the downstream. To get the timestamp of the error,
use materialize()
and apply timestamp(Scheduler)
.
timestamp
uses the provided Scheduler
for determining the current time upon receiving the
success item from the current Single
.scheduler
- the Scheduler
used for providing the current timeSingle
instanceNullPointerException
- if scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="io.reactivex:computation") public final @NonNull Single<Timed<T>> timestamp(@NonNull TimeUnit unit)
Single
with the current time of
its reception, using the computation
Scheduler
as time source,
then signals it as a Timed
instance.
If the current Single
is empty or fails, the resulting Single
will
pass along the signals to the downstream. To get the timestamp of the error,
use materialize()
and apply timestamp(TimeUnit)
.
timestamp
uses the computation
Scheduler
,
for determining the current time upon receiving the
success item from the current Single
.unit
- the time unit for measurementSingle
instanceNullPointerException
- if unit
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<Timed<T>> timestamp(@NonNull TimeUnit unit, @NonNull Scheduler scheduler)
Single
with the current time of
its reception, using the given Scheduler
as time source,
then signals it as a Timed
instance.
If the current Single
is empty or fails, the resulting Single
will
pass along the signals to the downstream. To get the timestamp of the error,
use materialize()
and apply timestamp(TimeUnit, Scheduler)
.
timestamp
uses the provided Scheduler
,
which is used for determining the current time upon receiving the
success item from the current Single
.unit
- the time unit for measurementscheduler
- the Scheduler
used for providing the current timeSingle
instanceNullPointerException
- if unit
or scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final @NonNull Single<T> takeUntil(@NonNull CompletableSource other)
Single
that emits the item emitted by the current Single
until a CompletableSource
terminates. Upon
termination of other
, this will emit a CancellationException
rather than go to
SingleObserver.onSuccess(Object)
.
takeUntil
does not operate by default on a particular Scheduler
.other
- the CompletableSource
whose termination will cause takeUntil
to emit the item from the current
Single
Single
that emits the item emitted by the current Single
until such time as other
terminates.NullPointerException
- if other
is null
@BackpressureSupport(value=FULL) @CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <E> @NonNull Single<T> takeUntil(@NonNull Publisher<E> other)
Single
that emits the item emitted by the current Single
until a Publisher
emits an item or completes. Upon
emission of an item from other
, this will emit a CancellationException
rather than go to
SingleObserver.onSuccess(Object)
.
other
publisher is consumed in an unbounded fashion but will be
cancelled after the first item it produced.takeUntil
does not operate by default on a particular Scheduler
.E
- the type of items emitted by other
other
- the Publisher
whose first emitted item or completion will cause takeUntil
to emit CancellationException
if the current Single
hasn't completed till thenSingle
that emits the item emitted by the current Single
until such time as other
emits
its first itemNullPointerException
- if other
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="none") public final <E> @NonNull Single<T> takeUntil(@NonNull SingleSource<? extends E> other)
Single
that emits the item emitted by the current Single
until a second Single
emits an item. Upon
emission of an item from other
, this will emit a CancellationException
rather than go to
SingleObserver.onSuccess(Object)
.
takeUntil
does not operate by default on a particular Scheduler
.E
- the type of item emitted by other
other
- the Single
whose emitted item will cause takeUntil
to emit CancellationException
if the current Single
hasn't completed till thenSingle
that emits the item emitted by the current Single
until such time as other
emits its itemNullPointerException
- if other
is null
@CheckReturnValue @SchedulerSupport(value="io.reactivex:computation") @NonNull public final @NonNull Single<T> timeout(long timeout, @NonNull TimeUnit unit)
TimeoutException
if the current Single
doesn't signal a success value within the
specified timeout window.
timeout
signals the TimeoutException
on the computation
Scheduler
.timeout
- the timeout amountunit
- the time unitSingle
instanceNullPointerException
- if unit
is null
@CheckReturnValue @SchedulerSupport(value="custom") @NonNull public final @NonNull Single<T> timeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler)
TimeoutException
if the current Single
doesn't signal a success value within the
specified timeout window.
timeout
signals the TimeoutException
on the Scheduler
you specify.timeout
- the timeout amountunit
- the time unitscheduler
- the target Scheduler
where the timeout is awaited and the TimeoutException
signaledSingle
instanceNullPointerException
- if unit
or scheduler
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<T> timeout(long timeout, @NonNull TimeUnit unit, @NonNull Scheduler scheduler, @NonNull SingleSource<? extends T> fallback)
Single
and if it doesn't signal within the specified timeout window, it is
disposed and the other SingleSource
subscribed to.
timeout
subscribes to the other SingleSource
on the Scheduler
you specify.timeout
- the timeout amountunit
- the time unitscheduler
- the Scheduler
where the timeout is awaited and the subscription to other happensfallback
- the other SingleSource
that gets subscribed to if the current Single
times outSingle
instanceNullPointerException
- if unit
, scheduler
or fallback
is null
@CheckReturnValue @NonNull @SchedulerSupport(value="io.reactivex:computation") public final @NonNull Single<T> timeout(long timeout, @NonNull TimeUnit unit, @NonNull SingleSource<? extends T> fallback)
Single
and if it doesn't signal within the specified timeout window, it is
disposed and the other SingleSource
subscribed to.
timeout
subscribes to the other SingleSource
on
the computation
Scheduler
.timeout
- the timeout amountunit
- the time unitfallback
- the other SingleSource
that gets subscribed to if the current Single
times outSingle
instanceNullPointerException
- if fallback
or unit
is null
@CheckReturnValue @SchedulerSupport(value="none") public final <R> R to(@NonNull SingleConverter<T,? extends R> converter)
This allows fluent conversion to any other type.
to
does not operate by default on a particular Scheduler
.History: 2.1.7 - experimental
R
- the resulting object typeconverter
- the function that receives the current Single
instance and returns a valueNullPointerException
- if converter
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Completable ignoreElement()
Completable
that ignores the success value of this Single
and signals onComplete
instead.
ignoreElement
does not operate by default on a particular Scheduler
.Completable
instance@BackpressureSupport(value=FULL) @CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Flowable<T> toFlowable()
Single
into a Flowable
.
Flowable
honors the backpressure of the downstream consumer.toFlowable
does not operate by default on a particular Scheduler
.Flowable
instance@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Future<T> toFuture()
Future
representing the single value emitted by this Single
.
Cancelling the Future
will cancel the subscription to the current Single
.
toFuture
does not operate by default on a particular Scheduler
.Future
instance@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Maybe<T> toMaybe()
Single
into a Maybe
.
toMaybe
does not operate by default on a particular Scheduler
.Maybe
instance@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull Observable<T> toObservable()
Single
into an Observable
.
toObservable
does not operate by default on a particular Scheduler
.Observable
instance@CheckReturnValue @NonNull @SchedulerSupport(value="custom") public final @NonNull Single<T> unsubscribeOn(@NonNull Scheduler scheduler)
Single
which makes sure when a SingleObserver
disposes the Disposable
,
that call is propagated up on the specified Scheduler
.
unsubscribeOn
calls dispose()
of the upstream on the Scheduler
you specify.History: 2.0.9 - experimental
scheduler
- the target scheduler where to execute the disposalSingle
instanceNullPointerException
- if scheduler
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final <U,R> @NonNull Single<R> zipWith(@NonNull SingleSource<U> other, @NonNull BiFunction<? super T,? super U,? extends R> zipper)
Single
that emits the result of applying a specified function to the pair of items emitted by
the current Single
and another specified SingleSource
.
zipWith
does not operate by default on a particular Scheduler
.U
- the type of items emitted by the other
Single
R
- the type of items emitted by the resulting Single
other
- the other SingleSource
zipper
- a function that combines the pairs of items from the two SingleSource
s to generate the items to
be emitted by the resulting Single
Single
that pairs up values from the current Single
and the other
SingleSource
and emits the results of zipFunction
applied to these pairsNullPointerException
- if other
or zipper
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull TestObserver<T> test()
TestObserver
and subscribes it to this Single
.
test
does not operate by default on a particular Scheduler
.TestObserver
instance@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull TestObserver<T> test(boolean dispose)
TestObserver
optionally in cancelled state, then subscribes it to this Single
.
test
does not operate by default on a particular Scheduler
.dispose
- if true
, the TestObserver
will be cancelled before subscribing to this
Single
.TestObserver
instance@CheckReturnValue @SchedulerSupport(value="none") @NonNull public static <T> @NonNull Single<T> fromCompletionStage(@NonNull CompletionStage<T> stage)
CompletionStage
-based asynchronous calculation.
Note that the operator takes an already instantiated, running or terminated CompletionStage
.
If the CompletionStage
is to be created per consumer upon subscription, use defer(Supplier)
around fromCompletionStage
:
Single.defer(() -> Single.fromCompletionStage(createCompletionStage()));
If the CompletionStage
completes with null
, the resulting Single
is terminated with
a NullPointerException
.
Canceling the flow can't cancel the execution of the CompletionStage
because CompletionStage
itself doesn't support cancellation. Instead, the operator detaches from the CompletionStage
.
fromCompletionStage
does not operate by default on a particular Scheduler
.T
- the element type of the CompletionStage
stage
- the CompletionStage
to convert to Single
and signal its success value or errorSingle
instanceNullPointerException
- if stage
is null
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final <R> @NonNull Maybe<R> mapOptional(@NonNull Function<? super T,Optional<? extends R>> mapper)
Optional
and emits the contained item if not empty as a Maybe
.
mapOptional
does not operate by default on a particular Scheduler
.R
- the non-null
output typemapper
- the function that receives the upstream success item and should return a non-empty Optional
to emit as the success output or an empty Optional
to complete the Maybe
Maybe
instanceNullPointerException
- if mapper
is null
map(Function)
,
filter(Predicate)
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final @NonNull CompletionStage<T> toCompletionStage()
CompletionStage
.
The upstream can be canceled by converting the resulting CompletionStage
into
CompletableFuture
via CompletionStage.toCompletableFuture()
and
calling CompletableFuture.cancel(boolean)
on it.
The upstream will be also cancelled if the resulting CompletionStage
is converted to and
completed manually by CompletableFuture.complete(Object)
or CompletableFuture.completeExceptionally(Throwable)
.
toCompletionStage
does not operate by default on a particular Scheduler
.CompletionStage
instance@CheckReturnValue @SchedulerSupport(value="none") @BackpressureSupport(value=FULL) @NonNull public final <R> @NonNull Flowable<R> flattenStreamAsFlowable(@NonNull Function<? super T,? extends Stream<? extends R>> mapper)
Stream
and emits its
items to the downstream consumer as a Flowable
.
The operator closes the Stream
upon cancellation and when it terminates. The exceptions raised when
closing a Stream
are routed to the global error handler (RxJavaPlugins.onError(Throwable)
.
If a Stream
should not be closed, turn it into an Iterable
and use flattenAsFlowable(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.
Stream
on demand (i.e., when requested).flattenStreamAsFlowable
does not operate by default on a particular Scheduler
.R
- the element type of the Stream
and the output Flowable
mapper
- the function that receives the upstream success item and should
return a Stream
of values to emit.Flowable
instanceNullPointerException
- if mapper
is null
flattenAsFlowable(Function)
,
flattenStreamAsObservable(Function)
@CheckReturnValue @SchedulerSupport(value="none") @NonNull public final <R> @NonNull Observable<R> flattenStreamAsObservable(@NonNull Function<? super T,? extends Stream<? extends R>> mapper)
Stream
and emits its
items to the downstream consumer as an Observable
.
The operator closes the Stream
upon cancellation and when it terminates. The exceptions raised when
closing a Stream
are routed to the global error handler (RxJavaPlugins.onError(Throwable)
.
If a Stream
should not be closed, turn it into an Iterable
and use flattenAsObservable(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.
flattenStreamAsObservable
does not operate by default on a particular Scheduler
.R
- the element type of the Stream
and the output Observable
mapper
- the function that receives the upstream success item and should
return a Stream
of values to emit.Observable
instanceNullPointerException
- if mapper
is null
flattenAsObservable(Function)
,
flattenStreamAsFlowable(Function)