T - Type of the result of the single.public abstract class Single<T>
extends Object
SingleSource.Subscriber as such calls are
ambiguous about the intent whether the subscribe is part of the same source (a.k.a an operator) or it is a terminal
subscribe. If it is required to subscribe to a source, then a source adapter can be used to
convert to a SingleSource.| Modifier | Constructor and Description |
|---|---|
protected |
Single()
New instance.
|
| Modifier and Type | Method and Description |
|---|---|
Single<T> |
afterCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument after Cancellable.cancel() is
called for Subscriptions of the returned Single. |
Single<T> |
afterFinally(Runnable doFinally)
Invokes the
whenFinally Runnable argument after any of the following terminal
methods are called:
SingleSource.Subscriber.onSuccess(Object)
SingleSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
afterFinally(SingleTerminalSignalConsumer<? super T> doFinally)
Invokes the corresponding method on
afterFinally SingleTerminalSignalConsumer argument
after any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
SingleTerminalSignalConsumer.onSuccess(Object)
SingleSource.Subscriber.onError(Throwable) - invokes
SingleTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes SingleTerminalSignalConsumer.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
afterFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method on
afterFinally TerminalSignalConsumer argument
after any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
TerminalSignalConsumer.onComplete()
SingleSource.Subscriber.onError(Throwable) - invokes
TerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
afterOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument after
SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single. |
Single<T> |
afterOnSubscribe(Consumer<Cancellable> onSubscribe)
Invokes the
onSubscribe Consumer argument after
SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single. |
Single<T> |
afterOnSuccess(Consumer<? super T> onSuccess)
Invokes the
onSuccess Consumer argument after
SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single. |
Single<T> |
afterSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
Creates a new
SingleSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and
invokes all the SingleSource.Subscriber methods after the SingleSource.Subscribers of the returned
Single. |
static <T> Single<T> |
amb(Iterable<Single<? extends T>> singles)
Creates a new
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first. |
static <T> Single<T> |
amb(Single<? extends T>... singles)
Creates a new
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first. |
Single<T> |
ambWith(Single<T> other)
|
static <T> Single<T> |
anyOf(Iterable<Single<? extends T>> singles)
Creates a new
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first. |
static <T> Single<T> |
anyOf(Single<? extends T>... singles)
Creates a new
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first. |
Single<T> |
beforeCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument before Cancellable.cancel() is
called for Subscriptions of the returned Single. |
Single<T> |
beforeFinally(Runnable doFinally)
Invokes the
whenFinally Runnable argument before any of the following terminal
methods are called:
SingleSource.Subscriber.onSuccess(Object)
SingleSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
beforeFinally(SingleTerminalSignalConsumer<? super T> doFinally)
Invokes the corresponding method on
beforeFinally SingleTerminalSignalConsumer argument
before any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
SingleTerminalSignalConsumer.onSuccess(Object)
SingleSource.Subscriber.onError(Throwable) - invokes
SingleTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes SingleTerminalSignalConsumer.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
beforeFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method on
beforeFinally TerminalSignalConsumer argument
before any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
TerminalSignalConsumer.onComplete()
SingleSource.Subscriber.onError(Throwable) - invokes
TerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
beforeOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument before
SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single. |
Single<T> |
beforeOnSubscribe(Consumer<Cancellable> onSubscribe)
Invokes the
onSubscribe Consumer argument before
SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single. |
Single<T> |
beforeOnSuccess(Consumer<? super T> onSuccess)
Invokes the
onSuccess Consumer argument before
SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single. |
Single<T> |
beforeSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
Creates a new
SingleSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and
invokes all the SingleSource.Subscriber methods before the SingleSource.Subscribers of the returned
Single. |
static <T> Single<Collection<T>> |
collectUnordered(int maxConcurrency,
Single<? extends T>... singles)
Asynchronously collects results of the passed
Singles into a single Collection. |
static <T> Single<Collection<T>> |
collectUnordered(Iterable<? extends Single<? extends T>> singles)
Asynchronously collects results of individual
Singles returned by the passed Iterable into a
single Collection. |
static <T> Single<Collection<T>> |
collectUnordered(Iterable<? extends Single<? extends T>> singles,
int maxConcurrency)
Asynchronously collects results of individual
Singles returned by the passed Iterable into a
single Collection. |
static <T> Single<Collection<T>> |
collectUnordered(Single<? extends T>... singles)
Asynchronously collects results of the passed
Singles into a single Collection. |
static <T> Single<Collection<T>> |
collectUnorderedDelayError(int maxConcurrency,
Single<? extends T>... singles)
Asynchronously collects results of the passed
Singles into a single Collection. |
static <T> Single<Collection<T>> |
collectUnorderedDelayError(Iterable<? extends Single<? extends T>> singles)
Asynchronously collects results of individual
Singles returned by the passed Iterable into a
single Collection. |
static <T> Single<Collection<T>> |
collectUnorderedDelayError(Iterable<? extends Single<? extends T>> singles,
int maxConcurrency)
Asynchronously collects results of individual
Singles returned by the passed Iterable into a
single Collection. |
static <T> Single<Collection<T>> |
collectUnorderedDelayError(Single<? extends T>... singles)
Asynchronously collects results of the passed
Singles into a single Collection. |
Single<T> |
concat(Completable next)
Returns a
Single that emits the result of this Single after next Completable
terminates successfully. |
Publisher<T> |
concat(Publisher<? extends T> next)
|
Publisher<T> |
concat(Publisher<? extends T> next,
boolean deferSubscribe)
|
Publisher<T> |
concat(Single<? extends T> next)
|
static <T> Single<T> |
defer(Supplier<? extends Single<? extends T>> singleSupplier)
Defer creation of a
Single till it is subscribed to. |
static <T> Single<T> |
failed(Throwable cause)
Creates a realized
Single which always completes with the provided error cause. |
<R> Single<R> |
flatMap(Function<? super T,? extends Single<? extends R>> next)
|
Completable |
flatMapCompletable(Function<? super T,? extends Completable> next)
|
<R> Publisher<R> |
flatMapPublisher(Function<? super T,? extends Publisher<? extends R>> next)
|
static <T> Single<T> |
fromCallable(Callable<T> callable)
|
static <T> Single<T> |
fromFuture(Future<? extends T> future)
|
static <T> Single<T> |
fromStage(CompletionStage<? extends T> stage)
Convert from a
CompletionStage to a Single. |
static <T> Single<T> |
fromSupplier(Supplier<T> supplier)
|
protected abstract void |
handleSubscribe(SingleSource.Subscriber<? super T> subscriber)
Handles a subscriber to this
Single. |
Single<T> |
idleTimeout(Duration duration)
Deprecated.
Use
timeout(Duration). |
Single<T> |
idleTimeout(Duration duration,
Executor timeoutExecutor)
Deprecated.
|
Single<T> |
idleTimeout(long duration,
TimeUnit unit)
Deprecated.
|
Single<T> |
idleTimeout(long duration,
TimeUnit unit,
Executor timeoutExecutor)
Deprecated.
|
Completable |
ignoreElement()
Ignores the result of this
Single and forwards the termination signal to the returned
Completable. |
<R> Single<R> |
liftAsync(SingleOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators.
|
<R> Single<R> |
liftSync(SingleOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators.
|
<R> Single<R> |
map(Function<? super T,? extends R> mapper)
Maps the result of this single to a different type.
|
static <T> Single<T> |
never()
Creates a
Single that never terminates. |
<E extends Throwable> |
onErrorMap(Class<E> type,
Function<? super E,? extends Throwable> mapper)
Transform errors emitted on this
Single which match type into a different error. |
Single<T> |
onErrorMap(Function<? super Throwable,? extends Throwable> mapper)
Transform errors emitted on this
Single into a different error. |
Single<T> |
onErrorMap(Predicate<? super Throwable> predicate,
Function<? super Throwable,? extends Throwable> mapper)
Transform errors emitted on this
Single which match predicate into a different error. |
<E extends Throwable> |
onErrorResume(Class<E> type,
Function<? super E,? extends Single<? extends T>> nextFactory)
|
Single<T> |
onErrorResume(Function<? super Throwable,? extends Single<? extends T>> nextFactory)
|
Single<T> |
onErrorResume(Predicate<? super Throwable> predicate,
Function<? super Throwable,? extends Single<? extends T>> nextFactory)
|
<E extends Throwable> |
onErrorReturn(Class<E> type,
Function<? super E,? extends T> itemSupplier)
Transform errors emitted on this
Single which match type into
SingleSource.Subscriber.onSuccess(Object) signal (e.g. |
Single<T> |
onErrorReturn(Function<? super Throwable,? extends T> itemSupplier)
Transform errors emitted on this
Single into SingleSource.Subscriber.onSuccess(Object) signal
(e.g. |
Single<T> |
onErrorReturn(Predicate<? super Throwable> predicate,
Function<? super Throwable,? extends T> itemSupplier)
Transform errors emitted on this
Single which match predicate into
SingleSource.Subscriber.onSuccess(Object) signal (e.g. |
Single<T> |
publishAndSubscribeOn(Executor executor)
Deprecated.
This operator has been deprecated because of upcoming behavior changes in how offloading via
operators is done. Originally offloading for subscribe/subscription was applied at the "bottom" of chain
(logically the last operator in the chain closest to the subscriber), and offloading for subscriber was applied
at the "top" of the operator chain (logically the first operator in the chain after the async source). The
current offloading doesn't respect the order in which the operators are applied, the offloading is the same
regardless of where the operators are placed in the chain. However, this behavior will soon change to instead
respect operator placement order and apply offloading exactly where the offloading operators are applied in the
chain. This change in behavior means that it no longer makes sense to fuse the offloading of publish and
subscribe as the location of the operators in the chain will now be significant. Publish and subscribe
offloading, when required, will typically be placed in different locations. Use separate, appropriately placed,
subscribeOn(Executor) and publishOn(Executor) operators instead. |
Single<T> |
publishAndSubscribeOnOverride(Executor executor)
Deprecated.
This method will be removed in a future release. Consider switching to
publishAndSubscribeOn(Executor) and/or using Executor.execute(Runnable) for offloading. |
Single<T> |
publishOn(Executor executor)
|
Single<T> |
publishOnOverride(Executor executor)
Deprecated.
This method will be removed in a future release. Consider switching to
publishOn(Executor) and/or using Executor.execute(Runnable) for offloading. |
Single<T> |
recoverWith(Function<? super Throwable,? extends Single<? extends T>> nextFactory)
Deprecated.
|
Publisher<T> |
repeat(IntPredicate shouldRepeat)
|
Publisher<T> |
repeatWhen(IntFunction<? extends Completable> repeatWhen)
Re-subscribes to this
Single when it completes and the Completable returned by the supplied
IntFunction completes successfully. |
Single<T> |
retry(BiIntPredicate<Throwable> shouldRetry)
|
Single<T> |
retryWhen(BiIntFunction<Throwable,? extends Completable> retryWhen)
Re-subscribes to this
Single if an error is emitted and the Completable returned by the supplied
BiIntFunction completes successfully. |
Cancellable |
subscribe(Consumer<? super T> resultConsumer)
Subscribe to this
Single, emits the result to the passed Consumer and log any
SingleSource.Subscriber.onError(Throwable). |
protected void |
subscribeInternal(SingleSource.Subscriber<? super T> subscriber)
A internal subscribe method similar to
SingleSource.subscribe(Subscriber) which can be used by
different implementations to subscribe. |
Single<T> |
subscribeOn(Executor executor)
Creates a new
Single that will use the passed Executor to invoke the following methods:
All Cancellable methods.
The handleSubscribe(SingleSource.Subscriber) method.
This method does not override preceding Executors, if any, specified for this
Single. |
Single<T> |
subscribeOnOverride(Executor executor)
Deprecated.
This method will be removed in a future release. Consider switching to
subscribeOn(Executor) and/or using Executor.execute(Runnable) for offloading. |
Single<T> |
subscribeShareContext()
Signifies that when the returned
Single is subscribed to, the AsyncContext will be shared
instead of making a copy. |
static <T> Single<T> |
succeeded(T value)
Creates a realized
Single which always completes successfully with the provided value. |
Single<T> |
timeout(Duration duration)
|
Single<T> |
timeout(Duration duration,
Executor timeoutExecutor)
|
Single<T> |
timeout(long duration,
TimeUnit unit)
|
Single<T> |
timeout(long duration,
TimeUnit unit,
Executor timeoutExecutor)
|
Completable |
toCompletable()
Ignores the result of this
Single and forwards the termination signal to the returned
Completable. |
CompletionStage<T> |
toCompletionStage()
Convert this
Single to a CompletionStage. |
Future<T> |
toFuture()
Convert this
Single to a Future. |
Publisher<T> |
toPublisher()
Converts this
Single to a Publisher. |
Single<T> |
whenCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument when Cancellable.cancel() is called for
Subscriptions of the returned Single. |
Single<T> |
whenFinally(Runnable doFinally)
Invokes the
whenFinally Runnable argument exactly once, when any of the following terminal
methods are called:
SingleSource.Subscriber.onSuccess(Object)
SingleSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
whenFinally(SingleTerminalSignalConsumer<? super T> doFinally)
Invokes the corresponding method on
whenFinally SingleTerminalSignalConsumer argument when any
of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
SingleTerminalSignalConsumer.onSuccess(Object)
SingleSource.Subscriber.onError(Throwable) - invokes
SingleTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes SingleTerminalSignalConsumer.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
whenFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method on
whenFinally TerminalSignalConsumer argument when any
of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
TerminalSignalConsumer.onComplete()
SingleSource.Subscriber.onError(Throwable) - invokes
TerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()
for Subscriptions/SingleSource.Subscribers of the returned Single. |
Single<T> |
whenOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument when SingleSource.Subscriber.onError(Throwable) is called for
SingleSource.Subscribers of the returned Single. |
Single<T> |
whenOnSubscribe(Consumer<Cancellable> onSubscribe)
Invokes the
onSubscribe Consumer argument when
SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single. |
Single<T> |
whenOnSuccess(Consumer<? super T> onSuccess)
Invokes the
onSuccess Consumer argument when SingleSource.Subscriber.onSuccess(Object) is called for
SingleSource.Subscribers of the returned Single. |
Single<T> |
whenSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
Creates a new
SingleSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes methods on that SingleSource.Subscriber when the corresponding methods are called for SingleSource.Subscribers of
the returned Single. |
static <R> Single<R> |
zip(Function<? super Object[],? extends R> zipper,
Single<?>... singles)
Create a new
Single that emits the results of a specified zipper Function to items emitted by
singles. |
static <T1,T2,R> Single<R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
BiFunction<? super T1,? super T2,? extends R> zipper)
Create a new
Single that emits the results of a specified zipper BiFunction to items emitted
by s1 and s2. |
static <T1,T2,T3,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Function3<? super T1,? super T2,? super T3,? extends R> zipper)
|
static <T1,T2,T3,T4,R> |
zip(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
|
static <R> Single<R> |
zipDelayError(Function<? super Object[],? extends R> zipper,
Single<?>... singles)
Create a new
Single that emits the results of a specified zipper Function to items emitted by
singles. |
static <T1,T2,R> Single<R> |
zipDelayError(Single<? extends T1> s1,
Single<? extends T2> s2,
BiFunction<? super T1,? super T2,? extends R> zipper)
Create a new
Single that emits the results of a specified zipper BiFunction to items emitted
by s1 and s2. |
static <T1,T2,T3,R> |
zipDelayError(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Function3<? super T1,? super T2,? super T3,? extends R> zipper)
|
static <T1,T2,T3,T4,R> |
zipDelayError(Single<? extends T1> s1,
Single<? extends T2> s2,
Single<? extends T3> s3,
Single<? extends T4> s4,
Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
|
<T2,R> Single<R> |
zipWith(Single<? extends T2> other,
BiFunction<? super T,? super T2,? extends R> zipper)
Create a new
Single that emits the results of a specified zipper BiFunction to items emitted by
this and other. |
<T2,R> Single<R> |
zipWithDelayError(Single<? extends T2> other,
BiFunction<? super T,? super T2,? extends R> zipper)
Create a new
Single that emits the results of a specified zipper BiFunction to items emitted by
this and other. |
public final <R> Single<R> map(Function<? super T,? extends R> mapper)
Single.
This method provides a data transformation in sequential programming similar to:
T tResult = resultOfThisSingle();
R rResult = mapper.apply(tResult);
R - Type of the returned Single.mapper - To convert this result to other.Single that will now have the result of type R.public final Single<T> onErrorReturn(Function<? super Throwable,? extends T> itemSupplier)
Single into SingleSource.Subscriber.onSuccess(Object) signal
(e.g. swallows the error).
This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle();
try {
terminalOfThisSingle();
} catch (Throwable cause) {
return itemSupplier.apply(cause);
}
return result;
itemSupplier - returns the element to emit to SingleSource.Subscriber.onSuccess(Object).Single which transform errors emitted on this Single into
SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).public final <E extends Throwable> Single<T> onErrorReturn(Class<E> type, Function<? super E,? extends T> itemSupplier)
Single which match type into
SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).
This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle();
try {
terminalOfThisSingle();
} catch (Throwable cause) {
if (!type.isInstance(cause)) {
throw cause;
}
return itemSupplier.apply(cause);
}
return result;
E - The type of Throwable to transform.type - The Throwable type to filter, operator will not apply for errors which don't match this type.itemSupplier - returns the element to emit to SingleSource.Subscriber.onSuccess(Object).Single which transform errors emitted on this Single into
SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).public final Single<T> onErrorReturn(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends T> itemSupplier)
Single which match predicate into
SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).
This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle();
try {
terminalOfThisSingle();
} catch (Throwable cause) {
if (!predicate.test(cause)) {
throw cause;
}
return itemSupplier.apply(cause);
}
return result;
predicate - returns true if the Throwable should be transformed to
SingleSource.Subscriber.onSuccess(Object) signal. Returns false to propagate the error.itemSupplier - returns the element to emit to SingleSource.Subscriber.onSuccess(Object).Single which transform errors emitted on this Single into
SingleSource.Subscriber.onSuccess(Object) signal (e.g. swallows the error).public final Single<T> onErrorMap(Function<? super Throwable,? extends Throwable> mapper)
Single into a different error.
This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle();
try {
terminalOfThisSingle();
} catch (Throwable cause) {
throw mapper.apply(cause);
}
return result;
mapper - returns the error used to terminate the returned Single.Single which transform errors emitted on this Single into a different error.public final <E extends Throwable> Single<T> onErrorMap(Class<E> type, Function<? super E,? extends Throwable> mapper)
Single which match type into a different error.
This method provides a data transformation in sequential programming similar to:
T result = resultOfThisSingle();
try {
terminalOfThisSingle();
} catch (Throwable cause) {
if (type.isInstance(cause)) {
throw mapper.apply(cause);
} else {
throw cause;
}
}
return result;
E - The type of Throwable to transform.type - The Throwable type to filter, operator will not apply for errors which don't match this type.mapper - returns the error used to terminate the returned Single.Single which transform errors emitted on this Single into a different error.public final Single<T> onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends Throwable> mapper)
Single which match predicate into a different error.
This method provides a data transformation in sequential programming similar to:
T results = resultOfThisSingle();
try {
terminalOfThisSingle();
} catch (Throwable cause) {
if (predicate.test(cause)) {
throw mapper.apply(cause);
} else {
throw cause;
}
}
return result;
predicate - returns true if the Throwable should be transformed via mapper. Returns
false to propagate the original error.mapper - returns the error used to terminate the returned Single.Single which transform errors emitted on this Single into a different error.public final Single<T> onErrorResume(Function<? super Throwable,? extends Single<? extends T>> nextFactory)
Single by using another Single provided by the
passed nextFactory.
This method provides similar capabilities to a try/catch block in sequential programming:
T result;
try {
result = resultOfThisSingle();
} catch (Throwable cause) {
// Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw).
result = nextFactory.apply(cause);
}
return result;
public final <E extends Throwable> Single<T> onErrorResume(Class<E> type, Function<? super E,? extends Single<? extends T>> nextFactory)
Single which match type by using another Single
provided by the passed nextFactory.
This method provides similar capabilities to a try/catch block in sequential programming:
T result;
try {
result = resultOfThisSingle();
} catch (Throwable cause) {
if (type.isInstance(cause)) {
// Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw).
result = nextFactory.apply(cause);
} else {
throw cause;
}
}
return result;
E - The type of Throwable to transform.type - The Throwable type to filter, operator will not apply for errors which don't match this type.nextFactory - Returns the next Single, when this Single emits an error.Single that recovers from an error from this Single by using another
Single provided by the passed nextFactory.public final Single<T> onErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends Single<? extends T>> nextFactory)
Single which match predicate by using another
Single provided by the passed nextFactory.
This method provides similar capabilities to a try/catch block in sequential programming:
T result;
try {
result = resultOfThisSingle();
} catch (Throwable cause) {
if (predicate.test(cause)) {
// Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw).
result = nextFactory.apply(cause);
} else {
throw cause;
}
}
return result;
predicate - returns true if the Throwable should be transformed via nextFactory.
Returns false to propagate the original error.nextFactory - Returns the next Single, when this Single emits an error.Single that recovers from an error from this Single by using another
Single provided by the passed nextFactory.@Deprecated public final Single<T> recoverWith(Function<? super Throwable,? extends Single<? extends T>> nextFactory)
onErrorResume(Function).Single by using another Single provided by the
passed nextFactory.
This method provides similar capabilities to a try/catch block in sequential programming:
T result;
try {
result = resultOfThisSingle();
} catch (Throwable cause) {
// Note that nextFactory returning a error Single is like re-throwing (nextFactory shouldn't throw).
result = nextFactory.apply(cause);
}
return result;
public final <R> Single<R> flatMap(Function<? super T,? extends Single<? extends R>> next)
Single that mirrors emissions from the Single returned by next.
Any error emitted by this Single is forwarded to the returned Single.
This method is similar to map(Function) but the result is asynchronous, and provides a data
transformation in sequential programming similar to:
T tResult = resultOfThisSingle();
R rResult = mapper.apply(tResult); // Asynchronous result is flatten into a value by this operator.
public final Completable flatMapCompletable(Function<? super T,? extends Completable> next)
Completable that mirrors emissions from the Completable returned by next.
Any error emitted by this Single is forwarded to the returned Completable.
This method is similar to map(Function) but the result is asynchronous with either complete/error status
in sequential programming similar to:
T tResult = resultOfThisSingle();
mapper.apply(tResult); // Asynchronous result is flatten into a error or completion by this operator.
next - Function to give the next Completable.Completable that switches to the Completable returned by next after this
Single completes successfully.public final <R> Publisher<R> flatMapPublisher(Function<? super T,? extends Publisher<? extends R>> next)
Publisher that mirrors emissions from the Publisher returned by next.
Any error emitted by this Single is forwarded to the returned Publisher.
This method is similar to map(Function) but the result is asynchronous, and provides a data
transformation in sequential programming similar to:
T tResult = resultOfThisSingle();
// Asynchronous result from mapper is flatten into collection of values.
for (R rResult : mapper.apply(tResult)) {
// process rResult
}
public final Single<T> whenOnSuccess(Consumer<? super T> onSuccess)
onSuccess Consumer argument when SingleSource.Subscriber.onSuccess(Object) is called for
SingleSource.Subscribers of the returned Single.
The order in which onSuccess will be invoked relative to SingleSource.Subscriber.onSuccess(Object) is
undefined. If you need strict ordering see beforeOnSuccess(Consumer) and
afterOnSuccess(Consumer).
From a sequential programming point of view this method is roughly equivalent to the following:
T result = resultOfThisSingle();
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(result);
onSuccess.accept(result);
onSuccess - Invoked when SingleSource.Subscriber.onSuccess(Object) is called for
SingleSource.Subscribers of the returned Single. MUST NOT throw.Single.beforeOnSuccess(Consumer),
afterOnSuccess(Consumer)public final Single<T> whenOnError(Consumer<Throwable> onError)
onError Consumer argument when SingleSource.Subscriber.onError(Throwable) is called for
SingleSource.Subscribers of the returned Single.
The order in which onError will be invoked relative to SingleSource.Subscriber.onError(Throwable) is
undefined. If you need strict ordering see beforeOnError(Consumer) and
afterOnError(Consumer).
From a sequential programming point of view this method is roughly equivalent to the following:
try {
T result = resultOfThisSingle();
} catch (Throwable cause) {
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(cause);
onError.accept(cause);
}
onError - Invoked when SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the
returned Single. MUST NOT throw.Single.beforeOnError(Consumer),
afterOnError(Consumer)public final Single<T> whenFinally(Runnable doFinally)
whenFinally Runnable argument exactly once, when any of the following terminal
methods are called:
SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()SingleSource.Subscribers of the returned Single.
The order in which whenFinally will be invoked relative to the above methods is undefined. If you need
strict ordering see beforeFinally(Runnable) and afterFinally(Runnable).
From a sequential programming point of view this method is roughly equivalent to the following:
try {
T result = resultOfThisSingle();
} finally {
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.run();
}
doFinally - Invoked exactly once, when any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()SingleSource.Subscribers of the returned Single. MUST NOT throw.Single.beforeFinally(Runnable),
afterFinally(Runnable)public final Single<T> whenFinally(TerminalSignalConsumer doFinally)
whenFinally TerminalSignalConsumer argument when any
of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
TerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable) - invokes
TerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()SingleSource.Subscribers of the returned Single.
The order in which whenFinally will be invoked relative to the above methods is undefined. If you need
strict ordering see beforeFinally(TerminalSignalConsumer) and
afterFinally(TerminalSignalConsumer).
From a sequential programming point of view this method is roughly equivalent to the following:
T result;
try {
result = resultOfThisSingle();
} catch(Throwable t) {
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onError(t);
return;
}
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onComplete();
doFinally - For each subscribe of the returned Single, at most one method of this
TerminalSignalConsumer will be invoked.Single.beforeFinally(TerminalSignalConsumer),
afterFinally(TerminalSignalConsumer)public final Single<T> whenFinally(SingleTerminalSignalConsumer<? super T> doFinally)
whenFinally SingleTerminalSignalConsumer argument when any
of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
SingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable) - invokes
SingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes SingleTerminalSignalConsumer.cancel()SingleSource.Subscribers of the returned Single.
The order in which whenFinally will be invoked relative to the above methods is undefined. If you need
strict ordering see beforeFinally(SingleTerminalSignalConsumer) and
afterFinally(SingleTerminalSignalConsumer).
From a sequential programming point of view this method is roughly equivalent to the following:
T result;
try {
result = resultOfThisSingle();
} catch(Throwable t) {
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onError(t);
return;
}
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onSuccess(result);
doFinally - For each subscribe of the returned Single, at most one method of this
SingleTerminalSignalConsumer will be invoked.Single.beforeFinally(SingleTerminalSignalConsumer),
afterFinally(SingleTerminalSignalConsumer)public final Single<T> whenCancel(Runnable onCancel)
onCancel Runnable argument when Cancellable.cancel() is called for
Subscriptions of the returned Single.
The order in which whenFinally will be invoked relative to Cancellable.cancel() is undefined. If
you need strict ordering see beforeCancel(Runnable) and afterCancel(Runnable).
onCancel - Invoked when Cancellable.cancel() is called for Subscriptions of the
returned Single. MUST NOT throw.Single.beforeCancel(Runnable),
afterCancel(Runnable)@Deprecated public final Single<T> idleTimeout(long duration, TimeUnit unit)
timeout(long, TimeUnit).Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and
termination. The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).unit - The units for duration.Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).@Deprecated public final Single<T> idleTimeout(long duration, TimeUnit unit, Executor timeoutExecutor)
timeout(Duration, io.servicetalk.concurrent.Executor).Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and
termination. The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).unit - The units for duration.timeoutExecutor - The Executor to use for managing the timer notifications.Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).@Deprecated public final Single<T> idleTimeout(Duration duration)
timeout(Duration).Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and
termination. The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
SingleSource.Subscriber will via terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).@Deprecated public final Single<T> idleTimeout(Duration duration, Executor timeoutExecutor)
timeout(Duration, io.servicetalk.concurrent.Executor).Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and termination.
The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).timeoutExecutor - The Executor to use for managing the timer notifications.Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).public final Single<T> timeout(long duration, TimeUnit unit)
Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and
termination. The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).unit - The units for duration.Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).public final Single<T> timeout(long duration, TimeUnit unit, Executor timeoutExecutor)
Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and
termination. The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).unit - The units for duration.timeoutExecutor - The Executor to use for managing the timer notifications.Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).public final Single<T> timeout(Duration duration)
Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and
termination. The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
SingleSource.Subscriber will via terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).public final Single<T> timeout(Duration duration, Executor timeoutExecutor)
Single that will mimic the signals of this Single but will terminate with a
with a TimeoutException if time duration elapses between subscribe and termination.
The timer starts when the returned Single is subscribed.
In the event of timeout any Cancellable from SingleSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated SingleSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before SingleSource.Subscriber.onSuccess(Object).timeoutExecutor - The Executor to use for managing the timer notifications.Single that will mimic the signals of this Single but will terminate with a
TimeoutException if time duration elapses before SingleSource.Subscriber.onSuccess(Object).public final Publisher<T> concat(Single<? extends T> next)
Publisher that first emits the result of this Single and then subscribes and emits
result of next Single. Any error emitted by this Single or next Single is
forwarded to the returned Publisher.
This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
Pair<T, T> p = new Pair<>();
p.first = resultOfThisSingle();
p.second = nextSingle();
return p;
public final Single<T> concat(Completable next)
Single that emits the result of this Single after next Completable
terminates successfully.
next Completable will only be subscribed to after this Single terminates successfully.
Any error emitted by this Single or next Completable is forwarded to the returned
Single.
This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
T result = resultOfThisSingle();
nextCompletable(); // Note this either completes successfully, or throws an error.
return result;
next - Completable to concat.Single that emits the result of this Single after next Completable
terminates successfully.public final Publisher<T> concat(Publisher<? extends T> next)
Publisher that first emits the result of this Single and then subscribes and emits all
elements from next Publisher. Any error emitted by this Single or next
Publisher is forwarded to the returned Publisher.
Note: this method is an overload for concat(Publisher, boolean) with deferSubscribe equal to
false, which triggers subscribe to the next Publisher as soon as this
Single completes successfully.
This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = new ...;
results.add(resultOfThisSingle());
results.addAll(nextStream());
return results;
next - Publisher to concat.Publisher that first emits the result of this Single and then subscribes and emits
all elements from next Publisher.concat(Publisher, boolean)public final Publisher<T> concat(Publisher<? extends T> next, boolean deferSubscribe)
Publisher that first emits the result of this Single and then subscribes and emits all
elements from next Publisher. Any error emitted by this Single or next
Publisher is forwarded to the returned Publisher.
This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = new ...;
results.add(resultOfThisSingle());
results.addAll(nextStream());
return results;
next - Publisher to concat.deferSubscribe - if true subscribe to the next Publisher will be deferred until
demand is received. Otherwise, it subscribes to the next Publisher as soon as this
Single completes successfully. Choosing the deferred (true) behavior is important if the
next Publisher does not or might not support multiple subscribers (non-replayable). Choosing the
immediate subscribe (false) behavior may have better performance and may be a preferable choice for
replayable Publisher(s) or when eager subscribe is beneficial.Publisher that first emits the result of this Single and then subscribes and emits
all elements from next Publisher.public final <T2,R> Single<R> zipWith(Single<? extends T2> other, BiFunction<? super T,? super T2,? extends R> zipper)
Single that emits the results of a specified zipper BiFunction to items emitted by
this and other.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T> f1 = ...; // this
CompletableFuture<T2> other = ...;
CompletableFuture.allOf(f1, other).get(); // wait for all futures to complete
return zipper.apply(f1.get(), other.get());
T2 - The type of other.R - The result type of the zipper.other - The other Single to zip with.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper BiFunction to items emitted by
this and other.public final <T2,R> Single<R> zipWithDelayError(Single<? extends T2> other, BiFunction<? super T,? super T2,? extends R> zipper)
Single that emits the results of a specified zipper BiFunction to items emitted by
this and other. If any of the Singles terminate with an error, the returned
Single will wait for termination till all the other Singles have been subscribed and terminated,
and then terminate with the first error.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T> f1 = ...; // this
CompletableFuture<T2> other = ...;
CompletableFuture.allOf(f1, other).get(); // wait for all futures to complete
return zipper.apply(f1.get(), other.get());
T2 - The type of other.R - The result type of the zipper.other - The other Single to zip with.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper BiFunction to items emitted by
this and other.public final Single<T> retry(BiIntPredicate<Throwable> shouldRetry)
Single if an error is emitted and the passed BiIntPredicate returns
true.
This method may result in aThis method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
public T execute() {
return execute(0);
}
private T execute(int attempts) {
try {
return resultOfThisSingle();
} catch (Throwable cause) {
if (shouldRetry.apply(attempts + 1, cause)) {
return execute(attempts + 1);
} else {
throw cause;
}
}
}
shouldRetry - BiIntPredicate that given the retry count and the most recent Throwable
emitted from this
Single determines if the operation should be retried.Single that emits the result from this Single or re-subscribes if an error is emitted
and if the passed BiIntPredicate returned true.public final Single<T> retryWhen(BiIntFunction<Throwable,? extends Completable> retryWhen)
Single if an error is emitted and the Completable returned by the supplied
BiIntFunction completes successfully. If the returned Completable emits an error, the returned
Single terminates with that error.
This method may result in aThis method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
public T execute() {
return execute(0);
}
private T execute(int attempts) {
try {
return resultOfThisSingle();
} catch (Throwable cause) {
try {
shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally
execute(attempts + 1);
} catch (Throwable ignored) {
throw cause;
}
}
}
retryWhen - BiIntFunction that given the retry count and the most recent Throwable emitted
from this Single returns a Completable. If this Completable emits an error, that error is
emitted from the returned Single, otherwise, original Single is re-subscribed when this
Completable completes.Single that emits the result from this Single or re-subscribes if an error is emitted
and Completable returned by BiIntFunction completes successfully.public final Publisher<T> repeat(IntPredicate shouldRepeat)
Single when it completes and the passed IntPredicate returns true.
This method may result in aThis method provides a means to repeat an operation multiple times and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
List<T> results = new ...;
int i = 0;
do {
results.add(resultOfThisSingle());
} while (shouldRepeat.test(++i));
return results;
shouldRepeat - IntPredicate that given the repeat count determines if the operation should be
repeated.Publisher that emits all items from this Single and from all re-subscriptions whenever
the operation is repeated.public final Publisher<T> repeatWhen(IntFunction<? extends Completable> repeatWhen)
Single when it completes and the Completable returned by the supplied
IntFunction completes successfully. If the returned Completable emits an error, the returned
Single emits an error.
This method may result in aThis method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
List<T> results = new ...;
int i = 0;
while (true) {
results.add(resultOfThisSingle());
try {
repeatWhen.apply(++i); // Either throws or completes normally
} catch (Throwable cause) {
break;
}
}
return results;
repeatWhen - IntFunction that given the repeat count returns a Completable.
If this Completable emits an error repeat is terminated, otherwise, original Single is
re-subscribed when this Completable completes.Publisher that emits all items from this Single and from all re-subscriptions whenever
the operation is repeated.public final Single<T> beforeOnSubscribe(Consumer<Cancellable> onSubscribe)
onSubscribe Consumer argument before
SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single.public final Single<T> beforeOnSuccess(Consumer<? super T> onSuccess)
onSuccess Consumer argument before
SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
T result = resultOfThisSingle();
onSuccess.accept(result);
nextOperation(result);
public final Single<T> beforeOnError(Consumer<Throwable> onError)
onError Consumer argument before
SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
try {
T result = resultOfThisSingle();
} catch (Throwable cause) {
onError.accept(cause);
nextOperation(cause);
}
public final Single<T> beforeCancel(Runnable onCancel)
onCancel Runnable argument before Cancellable.cancel() is
called for Subscriptions of the returned Single.public final Single<T> beforeFinally(Runnable doFinally)
whenFinally Runnable argument before any of the following terminal
methods are called:
SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
try {
T result = resultOfThisSingle();
} finally {
doFinally.run();
nextOperation(); // Maybe notifying of cancellation, or termination
}
doFinally - Invoked before any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()SingleSource.Subscribers of the returned Single. MUST NOT throw.Single.public final Single<T> beforeFinally(TerminalSignalConsumer doFinally)
beforeFinally TerminalSignalConsumer argument
before any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
TerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable) - invokes
TerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
T result;
try {
result = resultOfThisSingle();
} catch(Throwable t) {
doFinally.onError(t);
nextOperation(); // Maybe notifying of cancellation, or termination
return;
}
doFinally.onComplete();
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally - For each subscribe of the returned Single, at most one method of this
TerminalSignalConsumer will be invoked.Single.public final Single<T> beforeFinally(SingleTerminalSignalConsumer<? super T> doFinally)
beforeFinally SingleTerminalSignalConsumer argument
before any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
SingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable) - invokes
SingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes SingleTerminalSignalConsumer.cancel()SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
T result;
try {
result = resultOfThisSingle();
} catch(Throwable t) {
doFinally.onError(t);
nextOperation(); // Maybe notifying of cancellation, or termination
return;
}
doFinally.onSuccess(result);
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally - For each subscribe of the returned Single, at most one method of this
SingleTerminalSignalConsumer will be invoked.Single.public final Single<T> beforeSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
SingleSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and
invokes all the SingleSource.Subscriber methods before the SingleSource.Subscribers of the returned
Single.public final Single<T> afterOnSubscribe(Consumer<Cancellable> onSubscribe)
onSubscribe Consumer argument after
SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single.public final Single<T> whenOnSubscribe(Consumer<Cancellable> onSubscribe)
onSubscribe Consumer argument when
SingleSource.Subscriber.onSubscribe(Cancellable) is called for SingleSource.Subscribers of the returned Single.
The order in which onSubscribe will be invoked relative to
SingleSource.Subscriber.onSubscribe(Cancellable) is undefined. If you need strict ordering see
beforeOnSubscribe(Consumer) and afterOnSubscribe(Consumer).
onSubscribe - Invoked when SingleSource.Subscriber.onSubscribe(Cancellable) is called for
SingleSource.Subscribers of the returned Single. MUST NOT throw.Single.beforeOnSubscribe(Consumer),
afterOnSubscribe(Consumer)public final Single<T> afterOnSuccess(Consumer<? super T> onSuccess)
onSuccess Consumer argument after
SingleSource.Subscriber.onSuccess(Object) is called for SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
T result = resultOfThisSingle();
nextOperation(result);
onSuccess.accept(result);
public final Single<T> afterOnError(Consumer<Throwable> onError)
onError Consumer argument after
SingleSource.Subscriber.onError(Throwable) is called for SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
try {
T result = resultOfThisSingle();
} catch (Throwable cause) {
nextOperation(cause);
onError.accept(cause);
}
public final Single<T> afterCancel(Runnable onCancel)
onCancel Runnable argument after Cancellable.cancel() is
called for Subscriptions of the returned Single.public final Single<T> afterFinally(Runnable doFinally)
whenFinally Runnable argument after any of the following terminal
methods are called:
SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
try {
T result = resultOfThisSingle();
} finally {
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.run();
}
doFinally - Invoked after any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object)SingleSource.Subscriber.onError(Throwable)Cancellable.cancel()SingleSource.Subscribers of the returned Single. MUST NOT throw.Single.public final Single<T> afterFinally(TerminalSignalConsumer doFinally)
afterFinally TerminalSignalConsumer argument
after any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
TerminalSignalConsumer.onComplete()SingleSource.Subscriber.onError(Throwable) - invokes
TerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
T result;
try {
result = resultOfThisSingle();
} catch(Throwable t) {
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onError(t);
return;
}
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onComplete();
doFinally - For each subscribe of the returned Single, at most one method of this
TerminalSignalConsumer will be invoked.Single.public final Single<T> afterFinally(SingleTerminalSignalConsumer<? super T> doFinally)
afterFinally SingleTerminalSignalConsumer argument
after any of the following terminal methods are called:
SingleSource.Subscriber.onSuccess(Object) - invokes
SingleTerminalSignalConsumer.onSuccess(Object)SingleSource.Subscriber.onError(Throwable) - invokes
SingleTerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes SingleTerminalSignalConsumer.cancel()SingleSource.Subscribers of the returned Single.
From a sequential programming point of view this method is roughly equivalent to the following:
T result;
try {
result = resultOfThisSingle();
} catch(Throwable t) {
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onError(t);
return;
}
nextOperation(); // Maybe notifying of cancellation, or termination
doFinally.onSuccess(result);
doFinally - For each subscribe of the returned Single, at most one method of this
SingleTerminalSignalConsumer will be invoked.Single.public final Single<T> afterSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
SingleSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and
invokes all the SingleSource.Subscriber methods after the SingleSource.Subscribers of the returned
Single.public final Single<T> whenSubscriber(Supplier<? extends SingleSource.Subscriber<? super T>> subscriberSupplier)
SingleSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes methods on that SingleSource.Subscriber when the corresponding methods are called for SingleSource.Subscribers of
the returned Single.subscriberSupplier - Creates a new SingleSource.Subscriber for each new subscribe and invokes methods on that
SingleSource.Subscriber when the corresponding methods are called for SingleSource.Subscribers of the returned
Single. SingleSource.Subscriber methods MUST NOT throw.Single.public final Single<T> publishOn(Executor executor)
Single that will use the passed Executor to invoke all SingleSource.Subscriber methods.
This method does not override preceding Executors, if any, specified for this
Single. Only subsequent operations, if any, added in this execution chain will use this
Executor. If such an override is required, publishOnOverride(Executor) can be used.@Deprecated public final Single<T> publishOnOverride(Executor executor)
publishOn(Executor) and/or using Executor.execute(Runnable) for offloading.Single that will use the passed Executor to invoke all SingleSource.Subscriber methods.
This method overrides preceding Executors, if any, specified for this Single.
That is to say preceding and subsequent operations for this execution chain will use this Executor for
invoking all SingleSource.Subscriber methods. If such an override is not required, publishOn(Executor) can be
used.public final Single<T> subscribeOn(Executor executor)
Single that will use the passed Executor to invoke the following methods:
Cancellable methods.handleSubscribe(SingleSource.Subscriber) method.Executors, if any, specified for this
Single. Only subsequent operations, if any, added in this execution chain will use this
Executor. If such an override is required, subscribeOnOverride(Executor) can be used.executor - Executor to use.Single that will use the passed Executor to invoke all methods of
Cancellable and handleSubscribe(SingleSource.Subscriber).@Deprecated public final Single<T> subscribeOnOverride(Executor executor)
subscribeOn(Executor) and/or using Executor.execute(Runnable) for offloading.Single that will use the passed Executor to invoke the following methods:
Cancellable methods.handleSubscribe(SingleSource.Subscriber) method.Executors, if any, specified for this Single.
That is to say preceding and subsequent operations for this execution chain will use this Executor for
invoking the above specified methods.
If such an override is not required, subscribeOn(Executor) can be used.@Deprecated public final Single<T> publishAndSubscribeOn(Executor executor)
subscribeOn(Executor) and publishOn(Executor) operators instead.Single that will use the passed Executor to invoke the following methods:
SingleSource.Subscriber methods.Cancellable methods.handleSubscribe(SingleSource.Subscriber) method.Executors, if any, specified for this
Single. Only subsequent operations, if any, added in this execution chain will use this
Executor. If such an override is required, publishAndSubscribeOnOverride(Executor) can be used.executor - Executor to use.Single that will use the passed Executor to invoke all methods
SingleSource.Subscriber, Cancellable and handleSubscribe(SingleSource.Subscriber).@Deprecated public final Single<T> publishAndSubscribeOnOverride(Executor executor)
publishAndSubscribeOn(Executor) and/or using Executor.execute(Runnable) for offloading.Single that will use the passed Executor to invoke the following methods:
SingleSource.Subscriber methods.Cancellable methods.handleSubscribe(SingleSource.Subscriber) method.Executors, if any, specified for this Single.
That is to say preceding and subsequent operations for this execution chain will use this Executor.
If such an override is not required, publishAndSubscribeOn(Executor) can be used.public final Single<T> subscribeShareContext()
Single is subscribed to, the AsyncContext will be shared
instead of making a copy.
This operator only impacts behavior if the returned Single is subscribed directly after this operator,
that means this must be the "last operator" in the chain for this to have an impact.
Single that will share the AsyncContext instead of making a
copy when subscribed to.public final <R> Single<R> liftSync(SingleOperator<? super T,? extends R> operator)
Returns a Single which will wrap the SingleSource.Subscriber using the provided operator
argument before subscribing to this Single.
Single<X> pub = ...;
pub.map(..) // A
.liftSync(original -> modified)
.afterFinally(..) // B
The original -> modified "operator" MUST be "synchronous" in that it does not interact
with the original SingleSource.Subscriber from outside the modified SingleSource.Subscriber or Cancellable
threads. That is to say this operator will not impact the Executor constraints already in place between
A and B above. If you need asynchronous behavior, or are unsure, see
liftAsync(SingleOperator).R - Type of the items emitted by the returned Single.operator - The custom operator logic. The input is the "original" SingleSource.Subscriber to this
Single and the return is the "modified" SingleSource.Subscriber that provides custom operator business
logic.Single which when subscribed, the operator argument will be used to wrap the
SingleSource.Subscriber before subscribing to this Single.liftAsync(SingleOperator)public final <R> Single<R> liftAsync(SingleOperator<? super T,? extends R> operator)
Returns a Single which will wrap the SingleSource.Subscriber using the provided operator
argument before subscribing to this Single.
Publisher<X> pub = ...;
pub.map(..) // Aw
.liftAsync(original -> modified)
.afterFinally(..) // B
The original -> modified "operator" MAY be "asynchronous" in that it may interact with the original
SingleSource.Subscriber from outside the modified SingleSource.Subscriber or Cancellable threads. More
specifically:
This behavior exists to prevent blocking code negatively impacting the thread that powers the upstream source of
data (e.g. an EventLoop).R - Type of the items emitted by the returned Single.operator - The custom operator logic. The input is the "original" SingleSource.Subscriber to this
Single and the return is the "modified" SingleSource.Subscriber that provides custom operator business
logic.Single which when subscribed, the operator argument will be used to wrap the
SingleSource.Subscriber before subscribing to this Single.liftSync(SingleOperator)public final Single<T> ambWith(Single<T> other)
Single that terminates with the result (either success or error) of either this
Single or the passed other Single, whichever terminates first.
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator will pick the first result from either of the futures.
return ft.get();
}
public final Publisher<T> toPublisher()
Single to a Publisher.Publisher that emits at most a single item which is emitted by this Single.public final Completable toCompletable()
Single and forwards the termination signal to the returned
Completable.Completable that mirrors the terminal signal from this Single.public final Completable ignoreElement()
Single and forwards the termination signal to the returned
Completable.Completable that mirrors the terminal signal from this Single.public final CompletionStage<T> toCompletionStage()
Single to a CompletionStage.CompletionStage that mirrors the terminal signal from this Single.public final Future<T> toFuture()
Single to a Future.Future that mirrors the terminal signal from this Single.protected final void subscribeInternal(SingleSource.Subscriber<? super T> subscriber)
SingleSource.subscribe(Subscriber) which can be used by
different implementations to subscribe.subscriber - SingleSource.Subscriber to subscribe for the result.public final Cancellable subscribe(Consumer<? super T> resultConsumer)
Single, emits the result to the passed Consumer and log any
SingleSource.Subscriber.onError(Throwable).protected abstract void handleSubscribe(SingleSource.Subscriber<? super T> subscriber)
Single.subscriber - the subscriber.public static <T> Single<T> succeeded(@Nullable T value)
Single which always completes successfully with the provided value.public static <T> Single<T> fromCallable(Callable<T> callable)
Single which when subscribed will invoke Callable.call() on the passed
Callable and emit the value returned by that invocation from the returned Single. Any error
emitted by the Callable will terminate the returned Single with the same error.
Blocking inside Callable.call() will in turn block the subscribe call to the returned Single. If
this behavior is undesirable then the returned Single should be offloaded using one of the operators that
offloads the subscribe call (eg: subscribeOn(Executor), publishAndSubscribeOn(Executor)).
public static <T> Single<T> fromSupplier(Supplier<T> supplier)
Single which when subscribed will invoke Supplier.get() on the passed
Supplier and emit the value returned by that invocation from the returned Single. Any error
emitted by the Supplier will terminate the returned Single with the same error.
Blocking inside Supplier.get() will in turn block the subscribe call to the returned Single. If
this behavior is undesirable then the returned Single should be offloaded using one of the operators that
offloads the subscribe call (eg: subscribeOn(Executor), publishAndSubscribeOn(Executor)).
public static <T> Single<T> failed(Throwable cause)
Single which always completes with the provided error cause.public static <T> Single<T> defer(Supplier<? extends Single<? extends T>> singleSupplier)
Single till it is subscribed to.T - Type of the Single.singleSupplier - Supplier to create a new Single every time the returned Single is
subscribed.Single that creates a new Single using singleSupplier every time
it is subscribed and forwards all items and terminal events from the newly created Single to its
SingleSource.Subscriber.public static <T> Single<T> fromFuture(Future<? extends T> future)
Future to a Single via Future.get().
Note that because Future only presents blocking APIs to extract the result, so the process of getting the
results will block. The caller of subscribe is responsible for offloading if necessary, and also offloading if
Cancellable.cancel() will be called and this operation may block.
To apply a timeout see timeout(long, TimeUnit) and related methods.
T - The data type the Future provides when complete.future - The Future to convert.Single that derives results from Future.timeout(long, TimeUnit)public static <T> Single<Collection<T>> collectUnordered(Iterable<? extends Single<? extends T>> singles)
Singles returned by the passed Iterable into a
single Collection.
This will actively subscribe to a limited number of Singles concurrently, in order to alter the defaults,
collectUnordered(Iterable, int) should be used.
If any of the Singles terminate with an error, returned Single will immediately terminate with
that error. In such a case, any in progress Singles will be cancelled. In order to delay error
termination use collectUnorderedDelayError(Iterable).
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
result.add(ft.get());
}
return result;
T - Type of the result of the individual Singlessingles - Iterable of Singles, results of which are to be collected.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.@SafeVarargs public static <T> Single<Collection<T>> collectUnordered(Single<? extends T>... singles)
Singles into a single Collection.
This will actively subscribe to a limited number of Singles concurrently, in order to alter the defaults,
collectUnordered(int, Single[]) should be used.
If any of the Singles terminate with an error, returned Single will immediately terminate with
that error. In such a case, any in progress Singles will be cancelled. In order to delay error
termination use collectUnorderedDelayError(Single[]).
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
result.add(ft.get());
}
return result;
T - Type of the result of the individual Singlessingles - Singles, results of which are to be collected.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.public static <T> Single<Collection<T>> collectUnordered(Iterable<? extends Single<? extends T>> singles, int maxConcurrency)
Singles returned by the passed Iterable into a
single Collection.
If any of the Singles terminate with an error, returned Single will immediately terminate with
that error. In such a case, any in progress Singles will be cancelled. In order to delay error
termination use collectUnorderedDelayError(Iterable, int).
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
result.add(ft.get());
}
return result;
T - Type of the result of the individual Singlessingles - Iterable of Singles, results of which are to be collected.maxConcurrency - Maximum number of Singles that will be active at any point in time.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.@SafeVarargs public static <T> Single<Collection<T>> collectUnordered(int maxConcurrency, Single<? extends T>... singles)
Singles into a single Collection.
If any of the Singles terminate with an error, returned Single will immediately terminate with
that error. In such a case, any in progress Singles will be cancelled. In order to delay error
termination use collectUnorderedDelayError(int, Single[]).
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
result.add(ft.get());
}
return result;
T - Type of the result of the individual SinglesmaxConcurrency - Maximum number of Singles that will be active at any point in time.singles - Singles, results of which are to be collected.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.public static <T> Single<Collection<T>> collectUnorderedDelayError(Iterable<? extends Single<? extends T>> singles)
Singles returned by the passed Iterable into a
single Collection.
This will actively subscribe to a limited number of Singles concurrently, in order to alter the defaults,
collectUnorderedDelayError(Iterable, int).
If any of the Singles terminate with an error, returned Single will wait for termination till all
the other Singles have been subscribed and terminated. If it is expected for the returned Single
to terminate on the first failing Single, collectUnordered(Iterable) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
List<Throwable> errors = ...; // assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
result.add(ft.get());
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return rResults;
}
createAndThrowACompositeException(errors);
T - Type of the result of the individual Singlessingles - Iterable of Singles, results of which are to be collected.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.@SafeVarargs public static <T> Single<Collection<T>> collectUnorderedDelayError(Single<? extends T>... singles)
Singles into a single Collection.
This will actively subscribe to a limited number of Singles concurrently, in order to alter the defaults,
collectUnordered(int, Single[]).
If any of the Singles terminate with an error, returned Single will wait for termination till all
the other Singles have been subscribed and terminated. If it is expected for the returned Single
to terminate on the first failing Single, collectUnordered(Single[]) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
List<Throwable> errors = ...; // assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
result.add(ft.get());
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return rResults;
}
createAndThrowACompositeException(errors);
T - Type of the result of the individual Singlessingles - Singles, results of which are to be collected.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.public static <T> Single<Collection<T>> collectUnorderedDelayError(Iterable<? extends Single<? extends T>> singles, int maxConcurrency)
Singles returned by the passed Iterable into a
single Collection.
If any of the Singles terminate with an error, returned Single will wait for termination till all
the other Singles have been subscribed and terminated. If it is expected for the returned Single
to terminate on the first failing Single, collectUnordered(Iterable, int) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
List<Throwable> errors = ...; // assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
result.add(ft.get());
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return rResults;
}
createAndThrowACompositeException(errors);
T - Type of the result of the individual Singlessingles - Iterable of Singles, results of which are to be collected.maxConcurrency - Maximum number of Singles that will be active at any point in time.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.@SafeVarargs public static <T> Single<Collection<T>> collectUnorderedDelayError(int maxConcurrency, Single<? extends T>... singles)
Singles into a single Collection.
If any of the Singles terminate with an error, returned Single will wait for termination till all
the other Singles have been subscribed and terminated. If it is expected for the returned Single
to terminate on the first failing Single, collectUnordered(Iterable, int) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> result = ...;// assume this is thread safe
List<Throwable> errors = ...; // assume this is thread safe
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
result.add(ft.get());
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return rResults;
}
createAndThrowACompositeException(errors);
T - Type of the result of the individual SinglesmaxConcurrency - Maximum number of Singles that will be active at any point in time.singles - Singles, results of which are to be collected.Single producing a Collection of all values produced by the individual Singles.
There is no guarantee of the order of the values in the produced Collection as compared to the order of
Singles passed to this method.public static <T> Single<T> fromStage(CompletionStage<? extends T> stage)
CompletionStage to a Single.
A best effort is made to propagate Cancellable.cancel() to the CompletionStage. Cancellation for
CompletionStage implementations will result in exceptional completion and invoke user
callbacks. If there is any blocking code involved in the cancellation process (including invoking user callbacks)
you should investigate if using an Executor is appropriate.
T - The data type the CompletionStage provides when complete.stage - The CompletionStage to convert.Single that derives results from CompletionStage.@SafeVarargs public static <T> Single<T> amb(Single<? extends T>... singles)
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator will pick the first result from any of the futures.
return ft.get();
}
T - Type of the result of the individual Singlessingles - Singles the result of which are to be ambiguated.Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.public static <T> Single<T> amb(Iterable<Single<? extends T>> singles)
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator will pick the first result from any of the futures.
return ft.get();
}
T - Type of the result of the individual Singlessingles - Singles the result of which are to be ambiguated.Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.@SafeVarargs public static <T> Single<T> anyOf(Single<? extends T>... singles)
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator will pick the first result from any of the futures.
return ft.get();
}
T - Type of the result of the individual Singlessingles - Singles the result of which are to be ambiguated.Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.public static <T> Single<T> anyOf(Iterable<Single<? extends T>> singles)
Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the Singles here)
// This is an approximation, this operator will pick the first result from any of the futures.
return ft.get();
}
T - Type of the result of the individual Singlessingles - Singles the result of which are to be ambiguated.Single that terminates with the result (either success or error) of whichever amongst the
passed singles that terminates first.public static <T1,T2,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, BiFunction<? super T1,? super T2,? extends R> zipper)
Single that emits the results of a specified zipper BiFunction to items emitted
by s1 and s2.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1
CompletableFuture<T2> f2 = ...; // s2
CompletableFuture.allOf(f1, f2).get(); // wait for all futures to complete
return zipper.apply(f1.get(), f2.get());
T1 - The type for the first Single.T2 - The type for the second Single.R - The result type of the zipper.s1 - The first Single to zip.s2 - The second Single to zip.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper BiFunction to items emitted by
s1 and s2.public static <T1,T2,R> Single<R> zipDelayError(Single<? extends T1> s1, Single<? extends T2> s2, BiFunction<? super T1,? super T2,? extends R> zipper)
Single that emits the results of a specified zipper BiFunction to items emitted
by s1 and s2. If any of the Singles terminate with an error, the returned Single
will wait for termination till all the other Singles have been subscribed and terminated, and then
terminate with the first error.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1
CompletableFuture<T2> f2 = ...; // s2
CompletableFuture.allOf(f1, f2).get(); // wait for all futures to complete
return zipper.apply(f1.get(), f2.get());
T1 - The type for the first Single.T2 - The type for the second Single.R - The result type of the zipper.s1 - The first Single to zip.s2 - The second Single to zip.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper BiFunction to items emitted by
s1 and s2.public static <T1,T2,T3,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Function3<? super T1,? super T2,? super T3,? extends R> zipper)
Single that emits the results of a specified zipper Function3 to items emitted by
s1, s2, and s3.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1
CompletableFuture<T2> f2 = ...; // s2
CompletableFuture<T3> f3 = ...; // s3
CompletableFuture.allOf(f1, f2, f3).get(); // wait for all futures to complete
return zipper.apply(f1.get(), f2.get(), f3.get());
T1 - The type for the first Single.T2 - The type for the second Single.T3 - The type for the third Single.R - The result type of the zipper.s1 - The first Single to zip.s2 - The second Single to zip.s3 - The third Single to zip.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper Function3 to items emitted by
s1, s2, and s3.public static <T1,T2,T3,R> Single<R> zipDelayError(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Function3<? super T1,? super T2,? super T3,? extends R> zipper)
Single that emits the results of a specified zipper Function3 to items emitted by
s1, s2, and s3. If any of the Singles terminate with an error, the returned
Single will wait for termination till all the other Singles have been subscribed and terminated,
and then terminate with the first error.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1
CompletableFuture<T2> f2 = ...; // s2
CompletableFuture<T3> f3 = ...; // s3
CompletableFuture.allOf(f1, f2, f3).get(); // wait for all futures to complete
return zipper.apply(f1.get(), f2.get(), f3.get());
T1 - The type for the first Single.T2 - The type for the second Single.T3 - The type for the third Single.R - The result type of the zipper.s1 - The first Single to zip.s2 - The second Single to zip.s3 - The third Single to zip.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper Function3 to items emitted by
s1, s2, and s3.public static <T1,T2,T3,T4,R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
Single that emits the results of a specified zipper Function4 to items emitted by
s1, s2, s3, and s4.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1
CompletableFuture<T2> f2 = ...; // s2
CompletableFuture<T3> f3 = ...; // s3
CompletableFuture<T4> f4 = ...; // s3
CompletableFuture.allOf(f1, f2, f3, f4).get(); // wait for all futures to complete
return zipper.apply(f1.get(), f2.get(), f3.get(), f4.get());
T1 - The type for the first Single.T2 - The type for the second Single.T3 - The type for the third Single.T4 - The type for the fourth Single.R - The result type of the zipper.s1 - The first Single to zip.s2 - The second Single to zip.s3 - The third Single to zip.s4 - The fourth Single to zip.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper Function4 to items emitted by
s1, s2, s3, and s4.public static <T1,T2,T3,T4,R> Single<R> zipDelayError(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> zipper)
Single that emits the results of a specified zipper Function4 to items emitted by
s1, s2, s3, and s4. If any of the Singles terminate with an error, the
returned Single will wait for termination till all the other Singles have been subscribed and
terminated, and then terminate with the first error.
From a sequential programming point of view this method is roughly equivalent to the following:
CompletableFuture<T1> f1 = ...; // s1
CompletableFuture<T2> f2 = ...; // s2
CompletableFuture<T3> f3 = ...; // s3
CompletableFuture<T4> f4 = ...; // s3
CompletableFuture.allOf(f1, f2, f3, f4).get(); // wait for all futures to complete
return zipper.apply(f1.get(), f2.get(), f3.get(), f4.get());
T1 - The type for the first Single.T2 - The type for the second Single.T3 - The type for the third Single.T4 - The type for the fourth Single.R - The result type of the zipper.s1 - The first Single to zip.s2 - The second Single to zip.s3 - The third Single to zip.s4 - The fourth Single to zip.zipper - Used to combine the completed results for each item from singles.Single that emits the results of a specified zipper Function4 to items emitted by
s1, s2, s3, and s4.public static <R> Single<R> zip(Function<? super Object[],? extends R> zipper, Single<?>... singles)
Single that emits the results of a specified zipper Function to items emitted by
singles.
From a sequential programming point of view this method is roughly equivalent to the following:
Function<? super CompletableFuture<?>[], ? extends R> zipper = ...;
CompletableFuture<?>[] futures = ...; // Provided Futures (analogous to the Singles here)
CompletableFuture.allOf(futures).get(); // wait for all futures to complete
return zipper.apply(futures);
R - The result type of the zipper.zipper - Used to combine the completed results for each item from singles.singles - The collection of Singles that when complete provides the results to "zip" (aka combine)
together.Single that emits the results of a specified zipper Function to items emitted by
singles.public static <R> Single<R> zipDelayError(Function<? super Object[],? extends R> zipper, Single<?>... singles)
Single that emits the results of a specified zipper Function to items emitted by
singles. If any of the Singles terminate with an error, the returned Single will wait for
termination till all the other Singles have been subscribed and terminated, and then terminate with the
first error.
From a sequential programming point of view this method is roughly equivalent to the following:
Function<? super CompletableFuture<?>[], ? extends R> zipper = ...;
CompletableFuture<?>[] futures = ...; // Provided Futures (analogous to the Singles here)
CompletableFuture.allOf(futures).get(); // wait for all futures to complete
return zipper.apply(futures);
R - The result type of the zipper.zipper - Used to combine the completed results for each item from singles.singles - The collection of Singles that when complete provides the results to "zip" (aka combine)
together.Single that emits the results of a specified zipper Function to items emitted by
singles.