public abstract class Completable
extends Object
CompletableSource.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 CompletableSource.| Modifier | Constructor and Description |
|---|---|
protected |
Completable()
New instance.
|
| Modifier and Type | Method and Description |
|---|---|
Completable |
afterCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument after Cancellable.cancel() is
called for Subscriptions of the returned Completable. |
Completable |
afterFinally(Runnable doFinally)
Invokes the
whenFinally Runnable argument after any of the following terminal
methods are called:
CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/CompletableSource.Subscribers of the returned Completable. |
Completable |
afterOnComplete(Runnable onComplete)
Invokes the
onComplete Runnable argument after CompletableSource.Subscriber.onComplete()
is called for CompletableSource.Subscribers of the returned Completable. |
Completable |
afterOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument after
CompletableSource.Subscriber.onError(Throwable) is called for CompletableSource.Subscribers of the returned Completable. |
Completable |
afterOnSubscribe(Consumer<Cancellable> onSubscribe)
Invokes the
onSubscribe Consumer argument after
CompletableSource.Subscriber.onSubscribe(Cancellable) is called for CompletableSource.Subscribers of the returned
Completable. |
Completable |
afterSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier)
Creates a new
CompletableSource.Subscriber (via the subscriberSupplier argument) on each call to
subscribe and invokes all the CompletableSource.Subscriber methods after the CompletableSource.Subscribers of the
returned Completable. |
Completable |
beforeCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument before Cancellable.cancel() is
called for Subscriptions of the returned Completable. |
Completable |
beforeFinally(Runnable doFinally)
Invokes the
whenFinally Runnable argument before any of the following terminal
methods are called:
CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/CompletableSource.Subscribers of the returned Completable. |
Completable |
beforeOnComplete(Runnable onComplete)
Invokes the
onComplete Runnable argument before CompletableSource.Subscriber.onComplete()
is called for CompletableSource.Subscribers of the returned Completable. |
Completable |
beforeOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument before
CompletableSource.Subscriber.onError(Throwable) is called for CompletableSource.Subscribers of the returned Completable. |
Completable |
beforeOnSubscribe(Consumer<Cancellable> onSubscribe)
Invokes the
onSubscribe Consumer argument before
CompletableSource.Subscriber.onSubscribe(Cancellable) is called for CompletableSource.Subscribers of the returned
Completable. |
Completable |
beforeSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier)
Creates a new
CompletableSource.Subscriber (via the subscriberSupplier argument) on each call to
subscribe and invokes all the CompletableSource.Subscriber methods before the CompletableSource.Subscribers of the
returned Completable. |
static Completable |
completed()
Creates a realized completed
Completable. |
Completable |
concat(Completable next)
Once this
Completable is terminated successfully, subscribe to next Completable
and propagate its terminal signal to the returned Completable. |
<T> Publisher<T> |
concat(Publisher<? extends T> next)
Once this
Completable is terminated successfully, subscribe to next Publisher
and propagate all emissions to the returned Publisher. |
<T> Single<T> |
concat(Single<? extends T> next)
Once this
Completable is terminated successfully, subscribe to next Single
and propagate the result to the returned Single. |
static Completable |
defer(Supplier<? extends Completable> completableSupplier)
Defer creation of a
Completable till it is subscribed to. |
static Completable |
failed(Throwable cause)
Creates a realized failed
Completable. |
static Completable |
fromFuture(Future<?> future)
|
static Completable |
fromRunnable(Runnable runnable)
Creates a
Completable which when subscribed will invoke Runnable.run() on the passed
Runnable and emit the value returned by that invocation from the returned Completable. |
static Completable |
fromStage(CompletionStage<?> stage)
Convert from a
CompletionStage to a Completable. |
protected abstract void |
handleSubscribe(CompletableSource.Subscriber subscriber)
Handles a subscriber to this
Completable. |
Completable |
idleTimeout(Duration duration)
Creates a new
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination. |
Completable |
idleTimeout(Duration duration,
Executor timeoutExecutor)
Creates a new
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination. |
Completable |
idleTimeout(long duration,
TimeUnit unit)
Creates a new
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination. |
Completable |
idleTimeout(long duration,
TimeUnit unit,
Executor timeoutExecutor)
Creates a new
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination. |
Completable |
liftAsync(CompletableOperator operator)
This method requires advanced knowledge of building operators.
|
Completable |
liftSync(CompletableOperator operator)
This method requires advanced knowledge of building operators.
|
Completable |
merge(Completable... other)
Merges this
Completable with the other Completables so that the resulting
Completable terminates successfully when all of these complete or terminates with an error when any one
terminates with an error. |
Completable |
merge(Iterable<? extends Completable> other)
Merges this
Completable with the other Completables so that the resulting
Completable terminates successfully when all of these complete or terminates with an error when any one
terminates with an error. |
<T> Publisher<T> |
merge(Publisher<? extends T> mergeWith)
Merges the passed
Publisher with this Completable. |
static Completable |
mergeAll(Completable... completables)
Returns a
Completable that terminates when all the passed Completable terminate. |
static Completable |
mergeAll(int maxConcurrency,
Completable... completables)
Returns a
Completable that terminates when all the passed Completable terminate. |
static Completable |
mergeAll(Iterable<? extends Completable> completables)
Returns a
Completable that terminates when all the passed Completable terminate. |
static Completable |
mergeAll(Iterable<? extends Completable> completables,
int maxConcurrency)
Returns a
Completable that terminates when all the passed Completable terminate. |
static Completable |
mergeAllDelayError(Completable... completables)
Returns a
Completable that terminates when all the passed Completable terminate. |
static Completable |
mergeAllDelayError(int maxConcurrency,
Completable... completables)
Returns a
Completable that terminates when all the passed Completable terminate. |
static Completable |
mergeAllDelayError(Iterable<? extends Completable> completables)
Returns a
Completable that terminates when all the passed Completable terminate. |
static Completable |
mergeAllDelayError(Iterable<? extends Completable> completables,
int maxConcurrency)
Returns a
Completable that terminates when all the passed Completable terminate. |
Completable |
mergeDelayError(Completable... other)
Merges this
Completable with the other Completables, and delays error notification until
all involved Completables terminate. |
Completable |
mergeDelayError(Iterable<? extends Completable> other)
Merges this
Completable with the other Completables, and delays error notification until
all involved Completables terminate. |
static Completable |
never()
Creates a
Completable that never terminates. |
Completable |
onErrorResume(Function<Throwable,? extends Completable> nextFactory)
Recover from any error emitted by this
Completable by using another Completable provided by the
passed nextFactory. |
Completable |
publishAndSubscribeOn(Executor executor)
Creates a new
Completable that will use the passed Executor to invoke the following methods:
All CompletableSource.Subscriber methods.
All Cancellable methods.
The handleSubscribe(CompletableSource.Subscriber) method.
This method does not override preceding Executors, if any, specified for this
Completable. |
Completable |
publishAndSubscribeOnOverride(Executor executor)
Creates a new
Completable that will use the passed Executor to invoke the following methods:
All CompletableSource.Subscriber methods.
All Cancellable methods.
The handleSubscribe(CompletableSource.Subscriber) method.
This method overrides preceding Executors, if any, specified for this Completable. |
Completable |
publishOn(Executor executor)
Creates a new
Completable that will use the passed Executor to invoke all CompletableSource.Subscriber
methods. |
Completable |
publishOnOverride(Executor executor)
Creates a new
Completable that will use the passed Executor to invoke all CompletableSource.Subscriber
methods. |
Publisher<Void> |
repeat(IntPredicate shouldRepeat)
|
Publisher<Void> |
repeatWhen(IntFunction<? extends Completable> repeatWhen)
Re-subscribes to this
Completable when it completes and the Completable returned by the supplied
IntFunction completes successfully. |
Completable |
retry(BiIntPredicate<Throwable> shouldRetry)
Re-subscribes to this
Completable if an error is emitted and the passed BiIntPredicate returns
true. |
Completable |
retryWhen(BiIntFunction<Throwable,? extends Completable> retryWhen)
Re-subscribes to this
Completable if an error is emitted and the Completable returned by the
supplied BiIntFunction completes successfully. |
Cancellable |
subscribe()
Subscribe to this
Completable and log any CompletableSource.Subscriber.onError(Throwable). |
Cancellable |
subscribe(Runnable onComplete)
Subscribe to this
Completable and log any CompletableSource.Subscriber.onError(Throwable). |
protected void |
subscribeInternal(CompletableSource.Subscriber subscriber)
A internal subscribe method similar to
CompletableSource.subscribe(Subscriber) which can be used by
different implementations to subscribe. |
Completable |
subscribeOn(Executor executor)
Creates a new
Completable that will use the passed Executor to invoke the following methods:
All Cancellable methods.
The handleSubscribe(CompletableSource.Subscriber) method.
This method does not override preceding Executors, if any, specified for this
Completable. |
Completable |
subscribeOnOverride(Executor executor)
Creates a new
Completable that will use the passed Executor to invoke the following methods:
All Cancellable methods.
The handleSubscribe(CompletableSource.Subscriber) method.
This method overrides preceding Executors, if any, specified for this Completable. |
Completable |
subscribeShareContext()
Signifies that when the returned
Completable is subscribed to, the AsyncContext will be shared
instead of making a copy. |
CompletionStage<Void> |
toCompletionStage()
Converts this
Completable to a CompletionStage. |
Future<Void> |
toFuture()
Converts this
Completable to a Future. |
<T> Publisher<T> |
toPublisher()
Converts this
Completable to a Publisher. |
Single<Void> |
toSingle()
Converts this
Completable to a Single. |
Completable |
whenCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument when Cancellable.cancel() is called for
Subscriptions of the returned Completable. |
Completable |
whenFinally(Runnable doFinally)
Invokes the
whenFinally Runnable argument exactly once, when any of the following terminal
methods are called:
CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/CompletableSource.Subscribers of the returned Completable. |
Completable |
whenOnComplete(Runnable onComplete)
Invokes the
onComplete Runnable argument when CompletableSource.Subscriber.onComplete() is called for
CompletableSource.Subscribers of the returned Completable. |
Completable |
whenOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument when CompletableSource.Subscriber.onError(Throwable) is called for
CompletableSource.Subscribers of the returned Completable. |
Completable |
whenOnSubscribe(Consumer<Cancellable> onSubscribe)
Invokes the
onSubscribe Consumer argument when
CompletableSource.Subscriber.onSubscribe(Cancellable) is called for CompletableSource.Subscribers of the returned
Completable. |
Completable |
whenSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier)
Creates a new
CompletableSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes methods on that CompletableSource.Subscriber when the corresponding methods are called for CompletableSource.Subscribers of
the returned Publisher. |
public final Completable onErrorResume(Function<Throwable,? extends Completable> nextFactory)
Completable by using another Completable provided by the
passed nextFactory.
This method provides similar capabilities to a try/catch block in sequential programming:
try {
resultOfThisCompletable();
} catch (Throwable cause) {
// Note that nextFactory returning a error Completable is like re-throwing (nextFactory shouldn't throw).
nextFactory.apply(cause);
}
nextFactory - Returns the next Completable, if this Completable emits an error.Completable that recovers from an error from this Completable by using another
Completable provided by the passed nextFactory.public final Completable whenOnComplete(Runnable onComplete)
onComplete Runnable argument when CompletableSource.Subscriber.onComplete() is called for
CompletableSource.Subscribers of the returned Completable.
The order in which onComplete will be invoked relative to CompletableSource.Subscriber.onComplete() is
undefined. If you need strict ordering see beforeOnComplete(Runnable) and
afterOnComplete(Runnable).
From a sequential programming point of view this method is roughly equivalent to the following:
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(result);
onComplete.run();
onComplete - Invoked when CompletableSource.Subscriber.onComplete() is called for CompletableSource.Subscribers of the returned
Completable. MUST NOT throw.Completable.beforeOnComplete(Runnable),
afterOnComplete(Runnable)public final Completable whenOnError(Consumer<Throwable> onError)
onError Consumer argument when CompletableSource.Subscriber.onError(Throwable) is called for
CompletableSource.Subscribers of the returned Completable.
The order in which onError will be invoked relative to CompletableSource.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 {
resultOfThisCompletable();
} catch (Throwable cause) {
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(cause);
onError.accept(cause);
}
onError - Invoked when CompletableSource.Subscriber.onError(Throwable) is called for CompletableSource.Subscribers of the
returned Completable. MUST NOT throw.Completable.beforeOnError(Consumer),
afterOnError(Consumer)public final Completable whenFinally(Runnable doFinally)
whenFinally Runnable argument exactly once, when any of the following terminal
methods are called:
CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()CompletableSource.Subscribers of the returned Completable.
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 {
resultOfThisCompletable();
} finally {
// NOTE: The order of operations here is not guaranteed by this method!
nextOperation(); // Maybe notifying of cancellation, or termination
whenFinally.run();
}
doFinally - Invoked exactly once, when any of the following terminal methods are called:
CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()CompletableSource.Subscribers of the returned Completable MUST NOT throw.Completable.afterFinally(Runnable),
beforeFinally(Runnable)public final Completable whenCancel(Runnable onCancel)
onCancel Runnable argument when Cancellable.cancel() is called for
Subscriptions of the returned Completable.
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 Completable. MUST NOT throw.Completable.beforeCancel(Runnable),
afterCancel(Runnable)public final Completable idleTimeout(long duration, TimeUnit unit)
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination.
The timer starts when the returned Completable is subscribed.
In the event of timeout any Cancellable from CompletableSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated CompletableSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before CompletableSource.Subscriber.onComplete().unit - The units for duration.Completable that will mimic the signals of this Completable but will terminate with
a TimeoutException if time duration elapses before CompletableSource.Subscriber.onComplete().public final Completable idleTimeout(long duration, TimeUnit unit, Executor timeoutExecutor)
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination.
The timer starts when the returned Completable is subscribed.
In the event of timeout any Cancellable from CompletableSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated CompletableSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before CompletableSource.Subscriber.onComplete().unit - The units for duration.timeoutExecutor - The Executor to use for managing the timer notifications.Completable that will mimic the signals of this Completable but will terminate with
a TimeoutException if time duration elapses before CompletableSource.Subscriber.onComplete().public final Completable idleTimeout(Duration duration)
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination.
The timer starts when the returned Completable is subscribed.
In the event of timeout any Cancellable from CompletableSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated CompletableSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before CompletableSource.Subscriber.onComplete().Completable that will mimic the signals of this Completable but will terminate with
a TimeoutException if time duration elapses before CompletableSource.Subscriber.onComplete().public final Completable idleTimeout(Duration duration, Executor timeoutExecutor)
Completable that will mimic the signals of this Completable but will terminate
with a TimeoutException if time duration elapses between subscribe and termination.
The timer starts when the returned Completable is subscribed.
In the event of timeout any Cancellable from CompletableSource.Subscriber.onSubscribe(Cancellable) will be
cancelled and the associated CompletableSource.Subscriber will be
terminated.
duration - The time duration which is allowed to elapse before CompletableSource.Subscriber.onComplete().timeoutExecutor - The Executor to use for managing the timer notifications.Completable that will mimic the signals of this Completable but will terminate with
a TimeoutException if time duration elapses before CompletableSource.Subscriber.onComplete().public final Completable concat(Completable next)
Completable is terminated successfully, subscribe to next Completable
and propagate its terminal signal to the returned Completable. Any error from this Completable
or next Completable are propagated to the returned Completable.
This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
resultOfThisCompletable();
nextCompletable();
next - Completable to subscribe after this Completable terminates successfully.Completable that emits the terminal signal of next Completable, after this
Completable has terminated successfully.public final <T> Single<T> concat(Single<? extends T> next)
Completable is terminated successfully, subscribe to next Single
and propagate the result to the returned Single. Any error from this Completable or next
Single are propagated to the returned Single.
This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
resultOfThisCompletable();
T result = resultOfNextSingle();
return result;
T - Type of result of the returned Single.next - Single to subscribe after this Completable terminates successfully.Single that emits the result of next Single, after this Completable
has terminated successfully.public final <T> Publisher<T> concat(Publisher<? extends T> next)
Completable is terminated successfully, subscribe to next Publisher
and propagate all emissions to the returned Publisher. Any error from this Completable or
next Publisher are propagated 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 ...;
resultOfThisCompletable();
results.addAll(nextStream());
return results;
T - Type of objects emitted from the returned Publisher.next - Publisher to subscribe after this Completable terminates successfully.Publisher that emits all items emitted from next Publisher, after this
Completable has terminated successfully.public final Completable merge(Completable... other)
Completable with the other Completables so that the resulting
Completable terminates successfully when all of these complete or terminates with an error when any one
terminates with an error.
This method provides a means to merge multiple asynchronous sources, fails-fast in the presence of any errors, and in sequential programming is similar to:
ExecutorService e = ...;
List<Future<Void>> futures = ...;
futures.add(e.submit(() -> resultOfThisCompletable()));
for (Completable c : other) {
futures.add(e.submit(() -> resultOfCompletable(c));
}
// This is an approximation, this operator does not provide any ordering guarantees for the results.
for (Future<Void> future : futures) {
future.get(); // Throws if the processing for this item failed.
}
other - Completables to merge.Completable that terminates successfully when this and all other Completables
complete or terminates with an error when any one terminates with an error.public final Completable merge(Iterable<? extends Completable> other)
Completable with the other Completables so that the resulting
Completable terminates successfully when all of these complete or terminates with an error when any one
terminates with an error.
This method provides a means to merge multiple asynchronous sources, fails-fast in the presence of any errors, and in sequential programming is similar to:
ExecutorService e = ...;
List<Future<Void>> futures = ...;
futures.add(e.submit(() -> resultOfThisCompletable()));
for (Completable c : other) {
futures.add(e.submit(() -> resultOfCompletable(c));
}
// This is an approximation, this operator does not provide any ordering guarantees for the results.
for (Future<Void> future : futures) {
future.get(); // Throws if the processing for this item failed.
}
other - Completables to merge.Completable that terminates successfully when this and all other Completables
complete or terminates with an error when any one terminates with an error.public final <T> Publisher<T> merge(Publisher<? extends T> mergeWith)
Publisher with this Completable.
The resulting Publisher emits all items emitted by the passed Publisher and terminates
successfully when both this Completable and the passed Publisher terminates successfully.
It terminates with an error when any one of this Completable or passed Publisher terminates with
an error.
ExecutorService e = ...;
Future<?> future1 = e.submit(() -> resultOfThisCompletable()));
Future<?> future2 = e.submit(() -> resultOfMergeWithStream());
// This is an approximation, this operator does not provide any ordering guarantees for the results.
future1.get(); // Throws if this Completable failed.
future2.get(); // Throws if mergeWith Publisher failed.
T - The value type of the resulting Publisher.mergeWith - the Publisher to merge inPublisher that emits all items emitted by the passed Publisher and terminates
successfully when both this Completable and the passed Publisher terminates successfully.
It terminates with an error when any one of this Completable or passed Publisher terminates with
an error.public final Completable mergeDelayError(Completable... other)
Completable with the other Completables, and delays error notification until
all involved Completables terminate.
Use merge(Completable...) if any error should immediately terminate the returned Completable.
This method provides a means to merge multiple asynchronous sources, delays throwing in the presence of any errors, and in sequential programming is similar to:
ExecutorService e = ...;
List<Future<Void>> futures = ...;
futures.add(e.submit(() -> resultOfThisCompletable()));
for (Completable c : other) {
futures.add(e.submit(() -> resultOfCompletable(c));
}
Throwable overallCause = null;
// This is an approximation, this operator does not provide any ordering guarantees for the results.
for (Future<Void> future : futures) {
try {
f.get();
} catch (Throwable cause) {
if (overallCause != null) {
overallCause = cause;
}
}
}
if (overallCause != null) {
throw overallCause;
}
other - Completables to merge.Completable that terminates after this Completable and all other
Completables. If all involved Completables terminate successfully then the return value will
terminate successfully. If any Completable terminates in an error, then the return value will also
terminate in an error.public final Completable mergeDelayError(Iterable<? extends Completable> other)
Completable with the other Completables, and delays error notification until
all involved Completables terminate.
Use merge(Iterable) if any error should immediately terminate the returned Completable.
This method provides a means to merge multiple asynchronous sources, delays throwing in the presence of any errors, and in sequential programming is similar to:
ExecutorService e = ...;
List<Future<Void>> futures = ...;
futures.add(e.submit(() -> resultOfThisCompletable()));
for (Completable c : other) {
futures.add(e.submit(() -> resultOfCompletable(c));
}
Throwable overallCause = null;
// This is an approximation, this operator does not provide any ordering guarantees for the results.
for (Future<Void> future : futures) {
try {
f.get();
} catch (Throwable cause) {
if (overallCause != null) {
overallCause = cause;
}
}
}
if (overallCause != null) {
throw overallCause;
}
other - Completables to merge.Completable that terminates after this Completable and all other
Completables. If all involved Completables terminate successfully then the return value will
terminate successfully. If any Completable terminates in an error, then the return value will also
terminate in an error.public final Completable retry(BiIntPredicate<Throwable> shouldRetry)
Completable if an error is emitted and the passed BiIntPredicate returns
true.
This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:
public T execute() {
return execute(0);
}
private T execute(int attempts) {
try {
resultOfThisCompletable();
} 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
Completable determines if the operation should be retried.Completable that completes with this Completable or re-subscribes if an error is
emitted and if the passed BiPredicate returned true.public final Completable retryWhen(BiIntFunction<Throwable,? extends Completable> retryWhen)
Completable if an error is emitted and the Completable returned by the
supplied BiIntFunction completes successfully. If the returned Completable emits an error, the
returned Completable terminates with that error.
This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:
public T execute() {
return execute(0);
}
private T execute(int attempts) {
try {
resultOfThisCompletable();
} 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 Completable returns a Completable. If this Completable emits an error, that
error is emitted from the returned Completable, otherwise, original Completable is re-subscribed
when this Completable completes.Completable that completes with this Completable or re-subscribes if an error is
emitted and Completable returned by BiFunction completes successfully.public final Publisher<Void> repeat(IntPredicate shouldRepeat)
Completable when it completes and the passed IntPredicate returns
true.
This method provides a means to repeat an operation multiple times and in sequential programming is similar to:
int i = 0;
do {
resultOfThisCompletable();
} while (shouldRepeat.test(++i));
shouldRepeat - IntPredicate that given the repeat count determines if the operation should be
repeatedPublisher that emits the value returned by the passed Supplier everytime this
Completable completes.public final Publisher<Void> repeatWhen(IntFunction<? extends Completable> repeatWhen)
Completable when it completes and the Completable returned by the supplied
IntFunction completes successfully. If the returned Completable emits an error, the returned
Completable emits an error.
This method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:
int i = 0;
while (true) {
resultOfThisCompletable();
try {
repeatWhen.apply(++i); // Either throws or completes normally
} catch (Throwable cause) {
break;
}
}
repeatWhen - IntFunction that given the repeat count returns a Completable.
If this Completable emits an error repeat is terminated, otherwise, original Completable is
re-subscribed when this Completable completes.Completable that completes after all re-subscriptions completes.public final Completable beforeOnSubscribe(Consumer<Cancellable> onSubscribe)
onSubscribe Consumer argument before
CompletableSource.Subscriber.onSubscribe(Cancellable) is called for CompletableSource.Subscribers of the returned
Completable.onSubscribe - Invoked before CompletableSource.Subscriber.onSubscribe(Cancellable) is called for
CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable beforeOnComplete(Runnable onComplete)
onComplete Runnable argument before CompletableSource.Subscriber.onComplete()
is called for CompletableSource.Subscribers of the returned Completable.
From a sequential programming point of view this method is roughly equivalent to the following:
resultOfThisCompletable();
onComplete.run();
nextOperation();
onComplete - Invoked before CompletableSource.Subscriber.onComplete() is called for
CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable beforeOnError(Consumer<Throwable> onError)
onError Consumer argument before
CompletableSource.Subscriber.onError(Throwable) is called for CompletableSource.Subscribers of the returned Completable.
From a sequential programming point of view this method is roughly equivalent to the following:
try {
resultOfThisCompletable();
} catch (Throwable cause) {
onError.accept(cause);
nextOperation(cause);
}
onError - Invoked before CompletableSource.Subscriber.onError(Throwable) is called for
CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable beforeCancel(Runnable onCancel)
onCancel Runnable argument before Cancellable.cancel() is
called for Subscriptions of the returned Completable.onCancel - Invoked before Cancellable.cancel() is called for Subscriptions of the
returned Completable. MUST NOT throw.Completable.public final Completable beforeFinally(Runnable doFinally)
whenFinally Runnable argument before any of the following terminal
methods are called:
CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()CompletableSource.Subscribers of the returned Completable.
try {
resultOfThisCompletable();
} finally {
whenFinally.run();
nextOperation(); // Maybe notifying of cancellation, or termination
}
doFinally - Invoked before any of the following terminal methods are called:
CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable beforeSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier)
CompletableSource.Subscriber (via the subscriberSupplier argument) on each call to
subscribe and invokes all the CompletableSource.Subscriber methods before the CompletableSource.Subscribers of the
returned Completable.subscriberSupplier - Creates a new CompletableSource.Subscriber on each call to subscribe and invokes all the
CompletableSource.Subscriber methods before the CompletableSource.Subscribers of the returned Completable.
CompletableSource.Subscriber methods MUST NOT throw.Completable.public final Completable afterOnSubscribe(Consumer<Cancellable> onSubscribe)
onSubscribe Consumer argument after
CompletableSource.Subscriber.onSubscribe(Cancellable) is called for CompletableSource.Subscribers of the returned
Completable.onSubscribe - Invoked after CompletableSource.Subscriber.onSubscribe(Cancellable) is called for
CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable whenOnSubscribe(Consumer<Cancellable> onSubscribe)
onSubscribe Consumer argument when
CompletableSource.Subscriber.onSubscribe(Cancellable) is called for CompletableSource.Subscribers of the returned
Completable.
The order in which onSubscribe will be invoked relative to
CompletableSource.Subscriber.onSubscribe(Cancellable) is undefined. If you need strict ordering see
beforeOnSubscribe(Consumer) and afterOnSubscribe(Consumer).
onSubscribe - Invoked when CompletableSource.Subscriber.onSubscribe(Cancellable) is called for
CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.beforeOnSubscribe(Consumer),
afterOnSubscribe(Consumer)public final Completable afterOnComplete(Runnable onComplete)
onComplete Runnable argument after CompletableSource.Subscriber.onComplete()
is called for CompletableSource.Subscribers of the returned Completable.
From a sequential programming point of view this method is roughly equivalent to the following:
resultOfThisCompletable();
nextOperation();
onComplete.run();
onComplete - Invoked after CompletableSource.Subscriber.onComplete() is called for
CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable afterOnError(Consumer<Throwable> onError)
onError Consumer argument after
CompletableSource.Subscriber.onError(Throwable) is called for CompletableSource.Subscribers of the returned Completable.
From a sequential programming point of view this method is roughly equivalent to the following:
try {
resultOfThisCompletable();
} catch (Throwable cause) {
nextOperation(cause);
onError.accept(cause);
}
onError - Invoked after CompletableSource.Subscriber.onError(Throwable) is called for
CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable afterCancel(Runnable onCancel)
onCancel Runnable argument after Cancellable.cancel() is
called for Subscriptions of the returned Completable.onCancel - Invoked after Cancellable.cancel() is called for Subscriptions of the
returned Completable. MUST NOT throw.Completable.public final Completable afterFinally(Runnable doFinally)
whenFinally Runnable argument after any of the following terminal
methods are called:
CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()CompletableSource.Subscribers of the returned Completable.
From a sequential programming point of view this method is roughly equivalent to the following:
try {
resultOfThisCompletable();
} finally {
nextOperation(); // Maybe notifying of cancellation, or termination
whenFinally.run();
}
doFinally - Invoked after any of the following terminal methods are called:
CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()CompletableSource.Subscribers of the returned Completable. MUST NOT throw.Completable.public final Completable afterSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier)
CompletableSource.Subscriber (via the subscriberSupplier argument) on each call to
subscribe and invokes all the CompletableSource.Subscriber methods after the CompletableSource.Subscribers of the
returned Completable.subscriberSupplier - Creates a new CompletableSource.Subscriber on each call to subscribe and invokes all the
CompletableSource.Subscriber methods after the CompletableSource.Subscribers of the returned Completable.
CompletableSource.Subscriber methods MUST NOT throw.Completable.public final Completable whenSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier)
CompletableSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes methods on that CompletableSource.Subscriber when the corresponding methods are called for CompletableSource.Subscribers of
the returned Publisher.subscriberSupplier - Creates a new CompletableSource.Subscriber for each new subscribe and invokes methods on that
CompletableSource.Subscriber when the corresponding methods are called for CompletableSource.Subscribers of the returned
Publisher. CompletableSource.Subscriber methods MUST NOT throw.Completable.public final Completable liftSync(CompletableOperator operator)
Returns a Completable which will wrap the CompletableSource.Subscriber using the provided operator argument
before subscribing to this Completable.
Completable<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 CompletableSource.Subscriber from outside the modified CompletableSource.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(CompletableOperator).operator - The custom operator logic. The input is the "original" CompletableSource.Subscriber to this
Completable and the return is the "modified" CompletableSource.Subscriber that provides custom operator business
logic.Completable that when subscribed, the operator argument will be used to wrap the
CompletableSource.Subscriber before subscribing to this Completable.liftAsync(CompletableOperator)public final Completable liftAsync(CompletableOperator operator)
Returns a Completable which will wrap the CompletableSource.Subscriber using the provided operator argument
before subscribing to this Completable.
Publisher<X> pub = ...;
pub.map(..) // A
.liftAsync(original -> modified)
.afterFinally(..) // B
The original -> modified "operator" MAY be "asynchronous" in that it may interact with the original
CompletableSource.Subscriber from outside the modified CompletableSource.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).operator - The custom operator logic. The input is the "original" CompletableSource.Subscriber to this
Completable and the return is the "modified" CompletableSource.Subscriber that provides custom operator business
logic.Completable that when subscribed, the operator argument will be used to wrap the
CompletableSource.Subscriber before subscribing to this Completable.liftSync(CompletableOperator)public final Completable publishOn(Executor executor)
Completable that will use the passed Executor to invoke all CompletableSource.Subscriber
methods.
This method does not override preceding Executors, if any, specified for this
Completable. 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.executor - Executor to use.Completable that will use the passed Executor to invoke all methods on the
CompletableSource.Subscriber.public final Completable publishOnOverride(Executor executor)
Completable that will use the passed Executor to invoke all CompletableSource.Subscriber
methods.
This method overrides preceding Executors, if any, specified for this Completable.
That is to say preceding and subsequent operations for this execution chain will use this Executor.
If such an override is not required, publishOn(Executor) can be used.executor - Executor to use.Completable that will use the passed Executor to invoke all methods of
CompletableSource.Subscriber, Cancellable and handleSubscribe(CompletableSource.Subscriber) both for the
returned Completable as well as this Completable.public final Completable subscribeOn(Executor executor)
Completable that will use the passed Executor to invoke the following methods:
Cancellable methods.handleSubscribe(CompletableSource.Subscriber) method.Executors, if any, specified for this
Completable. 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.Completable that will use the passed Executor to invoke all methods of
Cancellable and handleSubscribe(CompletableSource.Subscriber).public final Completable subscribeOnOverride(Executor executor)
Completable that will use the passed Executor to invoke the following methods:
Cancellable methods.handleSubscribe(CompletableSource.Subscriber) method.Executors, if any, specified for this Completable.
That is to say preceding and subsequent operations for this execution chain will use this Executor.
If such an override is not required, subscribeOn(Executor) can be used.executor - Executor to use.Completable that will use the passed Executor to invoke all methods of
Cancellable and handleSubscribe(CompletableSource.Subscriber) both for the returned
Completable as well as this Completable.public final Completable publishAndSubscribeOn(Executor executor)
Completable that will use the passed Executor to invoke the following methods:
CompletableSource.Subscriber methods.Cancellable methods.handleSubscribe(CompletableSource.Subscriber) method.Executors, if any, specified for this
Completable. 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.Completable that will use the passed Executor to invoke all methods
CompletableSource.Subscriber, Cancellable and handleSubscribe(CompletableSource.Subscriber).public final Completable publishAndSubscribeOnOverride(Executor executor)
Completable that will use the passed Executor to invoke the following methods:
CompletableSource.Subscriber methods.Cancellable methods.handleSubscribe(CompletableSource.Subscriber) method.Executors, if any, specified for this Completable.
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.executor - Executor to use.Completable that will use the passed Executor to invoke all methods of
CompletableSource.Subscriber, Cancellable and handleSubscribe(CompletableSource.Subscriber) both for the
returned Completable as well as this Completable.public final Completable subscribeShareContext()
Completable is subscribed to, the AsyncContext will be shared
instead of making a copy.
This operator only impacts behavior if the returned Completable is subscribed directly after this
operator, that means this must be the "last operator" in the chain for this to have an impact.
Completable that will share the AsyncContext instead of making a
copy when subscribed to.public final <T> Publisher<T> toPublisher()
Completable to a Publisher.
No PublisherSource.Subscriber.onNext(Object) signals will be delivered to the
returned Publisher. Only terminal signals will be delivered. If you need more control you should consider
using concat(Publisher).
T - The value type of the resulting Publisher.Publisher that mirrors the terminal signal from this Completable.public final Single<Void> toSingle()
Completable to a Single.Single that mirrors the terminal signal from this Completable.public final CompletionStage<Void> toCompletionStage()
Completable to a CompletionStage.CompletionStage that mirrors the terminal signal from this Completable.public final Future<Void> toFuture()
Completable to a Future.Future that mirrors the terminal signal from this Completable.protected final void subscribeInternal(CompletableSource.Subscriber subscriber)
CompletableSource.subscribe(Subscriber) which can be used by
different implementations to subscribe.subscriber - CompletableSource.Subscriber to subscribe for the result.public final Cancellable subscribe()
Completable and log any CompletableSource.Subscriber.onError(Throwable).Cancellable used to invoke Cancellable.cancel() on the parameter of
CompletableSource.Subscriber.onSubscribe(Cancellable) for this Completable.public final Cancellable subscribe(Runnable onComplete)
Completable and log any CompletableSource.Subscriber.onError(Throwable). Passed Runnable
is invoked when this Completable terminates successfully.onComplete - Runnable to invoke when this Completable terminates successfully.Cancellable used to invoke Cancellable.cancel() on the parameter of
CompletableSource.Subscriber.onSubscribe(Cancellable) for this Completable.protected abstract void handleSubscribe(CompletableSource.Subscriber subscriber)
Completable.
This method is invoked internally by Completable for every call to the
subscribeInternal(CompletableSource.Subscriber) method.
subscriber - the subscriber.public static Completable completed()
Completable.Completable.public static Completable fromRunnable(Runnable runnable)
Completable which when subscribed will invoke Runnable.run() on the passed
Runnable and emit the value returned by that invocation from the returned Completable. Any error
emitted by the Runnable will terminate the returned Completable with the same error.
Blocking inside Runnable.run() will in turn block the subscribe call to the returned Completable.
If this behavior is undesirable then the returned Completable should be offloaded using one of the
operators that offloads the subscribe call (eg: subscribeOn(Executor),
publishAndSubscribeOn(Executor)).
runnable - Runnable which is invoked before completion.Completable.public static Completable failed(Throwable cause)
Completable.cause - error that the returned Completable completes with.Completable.public static Completable never()
Completable that never terminates.Completable.public static Completable defer(Supplier<? extends Completable> completableSupplier)
Completable till it is subscribed to.completableSupplier - Supplier to create a new Completable for every call to
subscribeInternal(CompletableSource.Subscriber) to the returned Completable.Completable that creates a new Completable using completableFactory
for every call to subscribeInternal(CompletableSource.Subscriber) and forwards
the termination signal from the newly created Completable to its CompletableSource.Subscriber.public static Completable fromFuture(Future<?> future)
Future to a Completable 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 subscribeInternal(CompletableSource.Subscriber) is responsible for
offloading if necessary, and also offloading if Cancellable.cancel() will be called if this operation may
block.
To apply a timeout see idleTimeout(long, TimeUnit) and related methods.
future - The Future to convert.Completable that derives results from Future.idleTimeout(long, TimeUnit)public static Completable fromStage(CompletionStage<?> stage)
CompletionStage to a Completable.
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.
stage - The CompletionStage to convert.Completable that derives results from CompletionStage.public static Completable mergeAll(Iterable<? extends Completable> completables)
Completable that terminates when all the passed Completable terminate.
This will actively subscribe to a default number of Completables concurrently, in order to alter the
defaults, mergeAll(Iterable, int).
If any of the Completables terminate with an error, returned Completable will immediately
terminate with that error. In such a case, any in-progress Completables will be cancelled. In order to
delay error termination use mergeAllDelayError(Iterable).
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
ft.get();
}
completables - Iterable of Completables, results of which are to be collected.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.public static Completable mergeAll(Completable... completables)
Completable that terminates when all the passed Completable terminate.
This will actively subscribe to a default number of Completables concurrently, in order to alter the
defaults, mergeAll(int, Completable...) should be used.
If any of the Completables terminate with an error, returned Completable will immediately
terminate with that error. In such a case, any in-progress Completables will be cancelled.
In order to delay error termination use mergeAllDelayError(Completable...).
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
ft.get();
}
completables - Completables, results of which are to be collected.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.public static Completable mergeAll(Iterable<? extends Completable> completables, int maxConcurrency)
Completable that terminates when all the passed Completable terminate.
If any of the Completables terminate with an error, returned Completable will immediately
terminate with that error. In such a case, any in-progress Completables will be cancelled. In order to
delay error termination use mergeAllDelayError(Iterable, int).
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
ft.get();
}
completables - Iterable of Completables, results of which are to be collected.maxConcurrency - Maximum number of Completables that will be active at any point in time.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.public static Completable mergeAll(int maxConcurrency, Completable... completables)
Completable that terminates when all the passed Completable terminate.
If any of the Completables terminate with an error, returned Completable will immediately
terminate with that error. In such a case, any in-progress Completables will be cancelled.
In order to delay error termination use mergeAllDelayError(int, Completable...).
From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
ft.get();
}
maxConcurrency - Maximum number of Completables that will be active at any point in time.completables - Completables, results of which are to be collected.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.public static Completable mergeAllDelayError(Iterable<? extends Completable> completables)
Completable that terminates when all the passed Completable terminate.
This will actively subscribe to a default number of Completables concurrently, in order to alter the
defaults, mergeAllDelayError(Iterable, int) should be used.
If any of the Completables terminate with an error, returned Completable will wait for
termination till all the other Completables have been subscribed and terminated. If it is expected for
the returned Completable to terminate on the first failing Completable,
mergeAll(Iterable) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<Throwable> errors = ...; // assume this is thread safe
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
ft.get();
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return;
}
createAndThrowACompositeException(errors);
completables - Iterable of Completables, results of which are to be collected.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.public static Completable mergeAllDelayError(Completable... completables)
Completable that terminates when all the passed Completable terminate.
This will actively subscribe to a limited number of Singles concurrently, in order to alter the defaults,
mergeAll(int, Completable...) should be used.
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, mergeAll(Completable...) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<Throwable> errors = ...; // assume this is thread safe
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
ft.get();
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return;
}
createAndThrowACompositeException(errors);
completables - Completables, results of which are to be collected.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.public static Completable mergeAllDelayError(Iterable<? extends Completable> completables, int maxConcurrency)
Completable that terminates when all the passed Completable terminate.
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, mergeAll(Iterable, int) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<Throwable> errors = ...; // assume this is thread safe
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
ft.get();
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return;
}
createAndThrowACompositeException(errors);
completables - Iterable of Completables, results of which are to be collected.maxConcurrency - Maximum number of Completables that will be active at any point in time.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.public static Completable mergeAllDelayError(int maxConcurrency, Completable... completables)
Completable that terminates when all the passed Completable terminate.
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, mergeAll(Iterable, int) should be used.
From a sequential programming point of view this method is roughly equivalent to the following:
List<Throwable> errors = ...; // assume this is thread safe
for (Future<Void> ft: futures) { // Provided Futures (analogous to the Completables here)
// This is an approximation, this operator does not provide any ordering guarantees for the results.
try {
ft.get();
} catch(Throwable t) {
errors.add(t);
}
}
if (errors.isEmpty()) {
return;
}
createAndThrowACompositeException(errors);
maxConcurrency - Maximum number of Completables that will be active at any point in time.completables - Completables, results of which are to be collected.Completable that terminates successfully if all the provided Completables have
terminated successfully or any one of them has terminated with a failure.