Class Completable
- Direct Known Subclasses:
SubscribableCompletable
How to subscribe?
This class does not provide a way to subscribe using aCompletableSource.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
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal Completable
afterCancel
(Runnable onCancel) Invokes theonCancel
Runnable
argument afterCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.final Completable
afterFinally
(TerminalSignalConsumer doFinally) Invokes the corresponding method onafterFinally
TerminalSignalConsumer
argument after any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
CompletableSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
for Subscriptions/CompletableSource.Subscriber
s of the returnedCompletable
.final Completable
afterFinally
(Runnable doFinally) Invokes thewhenFinally
Runnable
argument after any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/CompletableSource.Subscriber
s of the returnedCompletable
.final Completable
afterOnComplete
(Runnable onComplete) Invokes theonComplete
Runnable
argument afterCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
afterOnError
(Consumer<Throwable> onError) Invokes theonError
Consumer
argument afterCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
afterOnSubscribe
(Consumer<Cancellable> onSubscribe) Invokes theonSubscribe
Consumer
argument afterCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
afterSubscriber
(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all theCompletableSource.Subscriber
methods after theCompletableSource.Subscriber
s of the returnedCompletable
.static Completable
amb
(Completable... completables) Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.static Completable
amb
(Iterable<Completable> completables) Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.final Completable
ambWith
(Completable other) Creates a newCompletable
that terminates with the result (either success or error) of either thisCompletable
or the passedother
Completable
, whichever terminates first.static Completable
anyOf
(Completable... completables) Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.static Completable
anyOf
(Iterable<Completable> completables) Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.final Completable
beforeCancel
(Runnable onCancel) Invokes theonCancel
Runnable
argument beforeCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.final Completable
beforeFinally
(TerminalSignalConsumer doFinally) Invokes the corresponding method onbeforeFinally
TerminalSignalConsumer
argument before any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
CompletableSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
for Subscriptions/CompletableSource.Subscriber
s of the returnedCompletable
.final Completable
beforeFinally
(Runnable doFinally) Invokes thewhenFinally
Runnable
argument before any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for Subscriptions/CompletableSource.Subscriber
s of the returnedCompletable
.final Completable
beforeOnComplete
(Runnable onComplete) Invokes theonComplete
Runnable
argument beforeCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
beforeOnError
(Consumer<Throwable> onError) Invokes theonError
Consumer
argument beforeCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
beforeOnSubscribe
(Consumer<Cancellable> onSubscribe) Invokes theonSubscribe
Consumer
argument beforeCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
beforeSubscriber
(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all theCompletableSource.Subscriber
methods before theCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
cache()
Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s.final Completable
cache
(int minSubscribers) Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s.final Completable
cache
(int minSubscribers, boolean cancelUpstream) Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s.final Completable
cache
(int minSubscribers, boolean cancelUpstream, Function<Throwable, Completable> terminalResubscribe) Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s.static Completable
Creates a realized completedCompletable
.final Completable
concat
(Completable next) Once thisCompletable
is terminated successfully, subscribe tonext
Completable
and propagate its terminal signal to the returnedCompletable
.final Completable
concat
(Completable... nexts) Once thisCompletable
is terminated successfully, subscribe to eachCompletable
innexts
in a sequential fashion after termination, and the final terminal signals is propagated to the returnedCompletable
.final <T> Publisher<T>
Once thisCompletable
is terminated successfully, subscribe tonext
Publisher
and propagate all emissions to the returnedPublisher
.final <T> Single<T>
Once thisCompletable
is terminated successfully, subscribe tonext
Single
and propagate the result to the returnedSingle
.static Completable
defer
(Supplier<? extends Completable> completableSupplier) Defer creation of aCompletable
till it is subscribed to.static Completable
Creates a realized failedCompletable
.static Completable
fromCallable
(Callable<Void> callable) Creates aCompletable
which when subscribed will invokeCallable.call()
on the passedCallable
and emit the value returned by that invocation from the returnedCompletable
.static Completable
fromFuture
(Future<?> future) static Completable
fromRunnable
(Runnable runnable) Creates aCompletable
which when subscribed will invokeRunnable.run()
on the passedRunnable
and emit the value returned by that invocation from the returnedCompletable
.static Completable
fromStage
(CompletionStage<?> stage) Convert from aCompletionStage
to aCompletable
.protected abstract void
handleSubscribe
(CompletableSource.Subscriber subscriber) Handles a subscriber to thisCompletable
.final Completable
liftAsync
(CompletableOperator operator) This method requires advanced knowledge of building operators.final Completable
liftSync
(CompletableOperator operator) This method requires advanced knowledge of building operators.final Completable
merge
(Completable other) Merges thisCompletable
with theother
Completable
so that the resultingCompletable
terminates successfully when both of these complete or either terminates with an error.final Completable
merge
(Completable... other) Merges thisCompletable
with theother
Completable
s so that the resultingCompletable
terminates successfully when all of these complete or any one terminates with an error.final <T> Publisher<T>
Merges the passedPublisher
with thisCompletable
.final Completable
merge
(Iterable<? extends Completable> other) Merges thisCompletable
with theother
Completable
s so that the resultingCompletable
terminates successfully when all of these complete or terminates with an error when any one terminates with an error.static Completable
mergeAll
(int maxConcurrency, Completable... completables) Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAll
(Completable... completables) Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAll
(Iterable<? extends Completable> completables) Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAll
(Iterable<? extends Completable> completables, int maxConcurrency) Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAllDelayError
(int maxConcurrency, Completable... completables) Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAllDelayError
(Completable... completables) Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAllDelayError
(Iterable<? extends Completable> completables) Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAllDelayError
(Iterable<? extends Completable> completables, int maxConcurrency) Returns aCompletable
that terminates when all the passedCompletable
terminate.final Completable
mergeDelayError
(Completable other) Merges thisCompletable
with theother
Completable
, and delays error notification until all involvedCompletable
s terminate.final Completable
mergeDelayError
(Completable... other) Merges thisCompletable
with theother
Completable
s, and delays error notification until all involvedCompletable
s terminate.final <T> Publisher<T>
mergeDelayError
(Publisher<? extends T> mergeWith) Merges the passedPublisher
with thisCompletable
.final Completable
mergeDelayError
(Iterable<? extends Completable> other) Merges thisCompletable
with theother
Completable
s, and delays error notification until all involvedCompletable
s terminate.static Completable
never()
Creates aCompletable
that never terminates.final Completable
Transform errors emitted on thisCompletable
into aCompletableSource.Subscriber.onComplete()
signal (e.g.final <E extends Throwable>
CompletableonErrorComplete
(Class<E> type) Transform errors emitted on thisCompletable
which matchtype
into aCompletableSource.Subscriber.onComplete()
signal (e.g.final Completable
onErrorComplete
(Predicate<? super Throwable> predicate) Transform errors emitted on thisCompletable
which matchpredicate
into aCompletableSource.Subscriber.onComplete()
signal (e.g.final <E extends Throwable>
CompletableonErrorMap
(Class<E> type, Function<? super E, ? extends Throwable> mapper) Transform errors emitted on thisCompletable
which matchtype
into a different error.final Completable
onErrorMap
(Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisCompletable
into a different error.final Completable
onErrorMap
(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisCompletable
which matchpredicate
into a different error.final <E extends Throwable>
CompletableonErrorResume
(Class<E> type, Function<? super E, ? extends Completable> nextFactory) Recover from errors emitted by thisCompletable
which matchtype
by using anotherCompletable
provided by the passednextFactory
.final Completable
onErrorResume
(Function<? super Throwable, ? extends Completable> nextFactory) Recover from any error emitted by thisCompletable
by using anotherCompletable
provided by the passednextFactory
.final Completable
onErrorResume
(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Completable> nextFactory) Recover from errors emitted by thisCompletable
which matchpredicate
by using anotherCompletable
provided by the passednextFactory
.final Completable
Creates a newCompletable
that will use the passedExecutor
to invoke allCompletableSource.Subscriber
methods.final Completable
publishOn
(Executor executor, BooleanSupplier shouldOffload) Creates a newCompletable
that may use the passedExecutor
to invoke allCompletableSource.Subscriber
methods.repeat
(IntPredicate shouldRepeat) repeatWhen
(IntFunction<? extends Completable> repeatWhen) Re-subscribes to thisCompletable
when it completes and theCompletable
returned by the suppliedIntFunction
completes successfully.final Completable
retry
(BiIntPredicate<Throwable> shouldRetry) Re-subscribes to thisCompletable
if an error is emitted and the passedBiIntPredicate
returnstrue
.final Completable
retryWhen
(BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisCompletable
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully.final Completable
setContextOnSubscribe
(ContextMap context) final Completable
Signifies that when the returnedCompletable
is subscribed to, theAsyncContext
will be shared instead of making acopy
.final Cancellable
Subscribe to thisCompletable
and log anyCompletableSource.Subscriber.onError(Throwable)
.final Cancellable
Subscribe to thisCompletable
and log anyCompletableSource.Subscriber.onError(Throwable)
.final Cancellable
Subscribe to thisCompletable
, invoke passedRunnable
when thisCompletable
terminates successfully or emit an error toConsumer
when it fails.protected final void
subscribeInternal
(CompletableSource.Subscriber subscriber) A internal subscribe method similar toCompletableSource.subscribe(Subscriber)
which can be used by different implementations to subscribe.final Completable
subscribeOn
(Executor executor) Creates a newCompletable
that will use the passedExecutor
to invoke the following methods: AllCancellable
methods. ThehandleSubscribe(CompletableSource.Subscriber)
method. This method does not override precedingExecutor
s, if any, specified forthis
Completable
.final Completable
subscribeOn
(Executor executor, BooleanSupplier shouldOffload) Creates a newCompletable
that may use the passedExecutor
to invoke the following methods: AllCancellable
methods. ThehandleSubscribe(CompletableSource.Subscriber)
method. This method does not override precedingExecutor
s, if any, specified forthis
Completable
.final Completable
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.final Completable
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.final Completable
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.final Completable
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.final CompletionStage<Void>
Converts thisCompletable
to aCompletionStage
.toFuture()
Converts thisCompletable
to aFuture
.final <T> Publisher<T>
Converts thisCompletable
to aPublisher
.toSingle()
Converts thisCompletable
to aSingle
.final Completable
whenCancel
(Runnable onCancel) Invokes theonCancel
Runnable
argument whenCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.final Completable
whenFinally
(TerminalSignalConsumer doFinally) Invokes the corresponding method onwhenFinally
TerminalSignalConsumer
argument when any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
CompletableSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
for Subscriptions/CompletableSource.Subscriber
s of the returnedCompletable
.final Completable
whenFinally
(Runnable doFinally) Invokes thewhenFinally
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.Subscriber
s of the returnedCompletable
.final Completable
whenOnComplete
(Runnable onComplete) Invokes theonComplete
Runnable
argument whenCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
whenOnError
(Consumer<Throwable> onError) Invokes theonError
Consumer
argument whenCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
whenOnSubscribe
(Consumer<Cancellable> onSubscribe) Invokes theonSubscribe
Consumer
argument whenCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.final Completable
whenSubscriber
(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes methods on thatCompletableSource.Subscriber
when the corresponding methods are called forCompletableSource.Subscriber
s of the returnedPublisher
.
-
Constructor Details
-
Completable
protected Completable()New instance.
-
-
Method Details
-
onErrorComplete
Transform errors emitted on thisCompletable
into aCompletableSource.Subscriber.onComplete()
signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
try { resultOfThisCompletable(); } catch (Throwable cause) { // ignored }
- Returns:
- A
Completable
which transform errors emitted on thisCompletable
into aCompletableSource.Subscriber.onComplete()
signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisCompletable
which matchtype
into aCompletableSource.Subscriber.onComplete()
signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
try { resultOfThisCompletable(); } catch (Throwable cause) { if (!type.isInstance(cause)) { throw cause; } }
- Type Parameters:
E
- TheThrowable
type.- Parameters:
type
- TheThrowable
type to filter, operator will not apply for errors which don't match this type.- Returns:
- A
Completable
which transform errors emitted on thisCompletable
which matchtype
into aCompletableSource.Subscriber.onComplete()
signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisCompletable
which matchpredicate
into aCompletableSource.Subscriber.onComplete()
signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
try { resultOfThisCompletable(); } catch (Throwable cause) { if (!predicate.test(cause)) { throw cause; } }
- Parameters:
predicate
- returnstrue
if theThrowable
should be transformed to anCompletableSource.Subscriber.onComplete()
signal. Returnsfalse
to propagate the error.- Returns:
- A
Completable
which transform errors emitted on thisCompletable
which matchpredicate
into aCompletableSource.Subscriber.onComplete()
signal (e.g. swallows the error). - See Also:
-
onErrorMap
Transform errors emitted on thisCompletable
into a different error.This method provides a data transformation in sequential programming similar to:
try { resultOfThisCompletable(); } catch (Throwable cause) { throw mapper.apply(cause); }
- Parameters:
mapper
- returns the error used to terminate the returnedCompletable
.- Returns:
- A
Completable
which transform errors emitted on thisCompletable
into a different error. - See Also:
-
onErrorMap
public final <E extends Throwable> Completable onErrorMap(Class<E> type, Function<? super E, ? extends Throwable> mapper) Transform errors emitted on thisCompletable
which matchtype
into a different error.This method provides a data transformation in sequential programming similar to:
try { resultOfThisCompletable(); } catch (Throwable cause) { if (type.isInstance(cause)) { throw mapper.apply(cause); } else { throw cause; } }
- Type Parameters:
E
- The type ofThrowable
to transform.- Parameters:
type
- TheThrowable
type to filter, operator will not apply for errors which don't match this type.mapper
- returns the error used to terminate the returnedCompletable
.- Returns:
- A
Completable
which transform errors emitted on thisCompletable
into a different error. - See Also:
-
onErrorMap
public final Completable onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisCompletable
which matchpredicate
into a different error.This method provides a data transformation in sequential programming similar to:
try { resultOfThisCompletable(); } catch (Throwable cause) { if (predicate.test(cause)) { throw mapper.apply(cause); } else { throw cause; } }
- Parameters:
predicate
- returnstrue
if theThrowable
should be transformed viamapper
. Returnsfalse
to propagate the original error.mapper
- returns the error used to terminate the returnedCompletable
.- Returns:
- A
Completable
which transform errors emitted on thisCompletable
into a different error. - See Also:
-
onErrorResume
public final Completable onErrorResume(Function<? super Throwable, ? extends Completable> nextFactory) Recover from any error emitted by thisCompletable
by using anotherCompletable
provided by the passednextFactory
.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); }
- Parameters:
nextFactory
- Returns the nextCompletable
, if thisCompletable
emits an error.- Returns:
- A
Completable
that recovers from an error from thisCompletable
by using anotherCompletable
provided by the passednextFactory
.
-
onErrorResume
public final <E extends Throwable> Completable onErrorResume(Class<E> type, Function<? super E, ? extends Completable> nextFactory) Recover from errors emitted by thisCompletable
which matchtype
by using anotherCompletable
provided by the passednextFactory
.This method provides similar capabilities to a try/catch block in sequential programming:
try { resultOfThisCompletable(); } catch (Throwable cause) { if (type.isInstance(cause)) { // Note nextFactory returning a error Completable is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } else { throw cause; } }
- Type Parameters:
E
- The type ofThrowable
to transform.- Parameters:
type
- TheThrowable
type to filter, operator will not apply for errors which don't match this type.nextFactory
- Returns the nextCompletable
, when thisCompletable
emits an error.- Returns:
- A
Completable
that recovers from an error from thisPublisher
by using anotherCompletable
provided by the passednextFactory
. - See Also:
-
onErrorResume
public final Completable onErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Completable> nextFactory) Recover from errors emitted by thisCompletable
which matchpredicate
by using anotherCompletable
provided by the passednextFactory
.This method provides similar capabilities to a try/catch block in sequential programming:
try { resultOfThisCompletable(); } catch (Throwable cause) { if (predicate.test(cause)) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } else { throw cause; } }
- Parameters:
predicate
- returnstrue
if theThrowable
should be transformed vianextFactory
. Returnsfalse
to propagate the original error.nextFactory
- Returns the nextCompletable
, when thisCompletable
emits an error.- Returns:
- A
Completable
that recovers from an error from thisCompletable
by using anotherCompletable
provided by the passednextFactory
. - See Also:
-
whenOnComplete
Invokes theonComplete
Runnable
argument whenCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.The order in which
onComplete
will be invoked relative toCompletableSource.Subscriber.onComplete()
is undefined. If you need strict ordering seebeforeOnComplete(Runnable)
andafterOnComplete(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();
- Parameters:
onComplete
- Invoked whenCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
. - See Also:
-
whenOnError
Invokes theonError
Consumer
argument whenCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.The order in which
onError
will be invoked relative toCompletableSource.Subscriber.onError(Throwable)
is undefined. If you need strict ordering seebeforeOnError(Consumer)
andafterOnError(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); }
- Parameters:
onError
- Invoked whenCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
. - See Also:
-
whenFinally
Invokes thewhenFinally
Runnable
argument exactly once, when any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
.The order in which
whenFinally
will be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(Runnable)
andafterFinally(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 doFinally.run(); }
- Parameters:
doFinally
- Invoked exactly once, when any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
MUST NOT throw.- Returns:
- The new
Completable
. - See Also:
-
whenFinally
Invokes the corresponding method onwhenFinally
TerminalSignalConsumer
argument when any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
CompletableSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
.The order in which
whenFinally
will be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(TerminalSignalConsumer)
andafterFinally(TerminalSignalConsumer)
.From a sequential programming point of view this method is roughly equivalent to the following:
try { resultOfThisCompletable(); } 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();
- Parameters:
doFinally
- For each subscribe of the returnedCompletable
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Completable
. - See Also:
-
whenCancel
Invokes theonCancel
Runnable
argument whenCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.The order in which
whenFinally
will be invoked relative toCancellable.cancel()
is undefined. If you need strict ordering seebeforeCancel(Runnable)
andafterCancel(Runnable)
.- Parameters:
onCancel
- Invoked whenCancellable.cancel()
is called for Subscriptions of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
. - See Also:
-
timeout
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedCompletable
is subscribed.In the event of timeout any
Cancellable
fromCompletableSource.Subscriber.onSubscribe(Cancellable)
will becancelled
and the associatedCompletableSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete()
.unit
- The units forduration
.- Returns:
- a new
Completable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses beforeCompletableSource.Subscriber.onComplete()
. - See Also:
-
timeout
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedCompletable
is subscribed.In the event of timeout any
Cancellable
fromCompletableSource.Subscriber.onSubscribe(Cancellable)
will becancelled
and the associatedCompletableSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete()
.unit
- The units forduration
.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Completable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses beforeCompletableSource.Subscriber.onComplete()
. - See Also:
-
timeout
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedCompletable
is subscribed.In the event of timeout any
Cancellable
fromCompletableSource.Subscriber.onSubscribe(Cancellable)
will becancelled
and the associatedCompletableSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete()
.- Returns:
- a new
Completable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses beforeCompletableSource.Subscriber.onComplete()
. - See Also:
-
timeout
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedCompletable
is subscribed.In the event of timeout any
Cancellable
fromCompletableSource.Subscriber.onSubscribe(Cancellable)
will becancelled
and the associatedCompletableSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete()
.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Completable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses beforeCompletableSource.Subscriber.onComplete()
. - See Also:
-
concat
Once thisCompletable
is terminated successfully, subscribe tonext
Completable
and propagate its terminal signal to the returnedCompletable
. Any error from thisCompletable
ornext
Completable
are propagated to the returnedCompletable
.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
resultOfThisCompletable(); nextCompletable();
- Parameters:
next
-Completable
to subscribe after thisCompletable
terminates successfully.- Returns:
- A
Completable
that emits the terminal signal ofnext
Completable
, after thisCompletable
has terminated successfully.
-
concat
Once thisCompletable
is terminated successfully, subscribe to eachCompletable
innexts
in a sequential fashion after termination, and the final terminal signals is propagated to the returnedCompletable
. Any error from thisCompletable
or fromnexts
Completable
are propagated to the returnedCompletable
.This method provide equivalent functionality as:
Completable original = ...; Completable[] nexts = ...; Completable result = original; for (int i = 0; i < nexts.length; ++i) { result = result.concat(nexts[i]); } return result;
- Parameters:
nexts
-Completable
s to subscribe after thisCompletable
terminates successfully.- Returns:
- A
Completable
that emits the terminal signal ofnexts
Completable
s, after thisCompletable
has terminated successfully.
-
concat
Once thisCompletable
is terminated successfully, subscribe tonext
Single
and propagate the result to the returnedSingle
. Any error from thisCompletable
ornext
Single
are propagated to the returnedSingle
.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;
- Type Parameters:
T
- Type of result of the returnedSingle
.- Parameters:
next
-Single
to subscribe after thisCompletable
terminates successfully.- Returns:
- A
Single
that emits the result ofnext
Single
, after thisCompletable
has terminated successfully.
-
concat
Once thisCompletable
is terminated successfully, subscribe tonext
Publisher
and propagate all emissions to the returnedPublisher
. Any error from thisCompletable
ornext
Publisher
are propagated to the returnedPublisher
.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;
- Type Parameters:
T
- Type of objects emitted from the returnedPublisher
.- Parameters:
next
-Publisher
to subscribe after thisCompletable
terminates successfully.- Returns:
- A
Publisher
that emits all items emitted fromnext
Publisher
, after thisCompletable
has terminated successfully.
-
merge
Merges thisCompletable
with theother
Completable
so that the resultingCompletable
terminates successfully when both of these complete or either 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())); futures.add(e.submit(() -> resultOfCompletable(other)); // 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. }
- Parameters:
other
-Completable
s to merge.- Returns:
Completable
that terminates successfully when this andother
Completable
s complete or terminates with an error when either terminates with an error.
-
merge
Merges thisCompletable
with theother
Completable
s so that the resultingCompletable
terminates successfully when all of these complete or 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. }
- Parameters:
other
-Completable
s to merge.- Returns:
Completable
that terminates successfully when this and allother
Completable
s complete or terminates with an error when any one terminates with an error.
-
merge
Merges thisCompletable
with theother
Completable
s so that the resultingCompletable
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. }
- Parameters:
other
-Completable
s to merge.- Returns:
Completable
that terminates successfully when this and allother
Completable
s complete or terminates with an error when any one terminates with an error.
-
merge
Merges the passedPublisher
with thisCompletable
.The resulting
Publisher
emits all items emitted by the passedPublisher
and terminates successfully when both thisCompletable
and the passedPublisher
terminates successfully. It terminates with an error when any one of thisCompletable
or passedPublisher
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.
- Type Parameters:
T
- The value type of the resultingPublisher
.- Parameters:
mergeWith
- thePublisher
to merge in- Returns:
Publisher
that emits all items emitted by the passedPublisher
and terminates successfully when both thisCompletable
and the passedPublisher
terminates successfully. It terminates with an error when any one of thisCompletable
or passedPublisher
terminates with an error.- See Also:
-
mergeDelayError
Merges the passedPublisher
with thisCompletable
.The resulting
Publisher
emits all items emitted by the passedPublisher
and terminates when both thisCompletable
and the passedPublisher
terminate. If either terminates with an error then the error will be propagated to the return value.ExecutorService e = ...; List<Future<Void>> futures = ...; futures.add(e.submit(() -> resultOfThisCompletable())); futures.add(e.submit(() -> resultOfMergeWithStream()); 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; }
- Type Parameters:
T
- The value type of the resultingPublisher
.- Parameters:
mergeWith
- thePublisher
to merge in- Returns:
Publisher
emits all items emitted by the passedPublisher
and terminates when both thisCompletable
and the passedPublisher
terminate. If either terminates with an error then the error will be propagated to the return value.- See Also:
-
mergeDelayError
Merges thisCompletable
with theother
Completable
, and delays error notification until all involvedCompletable
s terminate.Use
merge(Completable)
if any error should immediately terminate the returnedCompletable
.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())); futures.add(e.submit(() -> resultOfCompletable(other)); 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; }
- Parameters:
other
-Completable
to merge.- Returns:
Completable
that terminates afterthis
Completable
andother
Completable
. If all involvedCompletable
s terminate successfully then the return value will terminate successfully. If anyCompletable
terminates in an error, then the return value will also terminate in an error.
-
mergeDelayError
Merges thisCompletable
with theother
Completable
s, and delays error notification until all involvedCompletable
s terminate.Use
merge(Completable...)
if any error should immediately terminate the returnedCompletable
.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; }
- Parameters:
other
-Completable
s to merge.- Returns:
Completable
that terminates afterthis
Completable
and allother
Completable
s. If all involvedCompletable
s terminate successfully then the return value will terminate successfully. If anyCompletable
terminates in an error, then the return value will also terminate in an error.
-
mergeDelayError
Merges thisCompletable
with theother
Completable
s, and delays error notification until all involvedCompletable
s terminate.Use
merge(Iterable)
if any error should immediately terminate the returnedCompletable
.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; }
- Parameters:
other
-Completable
s to merge.- Returns:
Completable
that terminates afterthis
Completable
and allother
Completable
s. If all involvedCompletable
s terminate successfully then the return value will terminate successfully. If anyCompletable
terminates in an error, then the return value will also terminate in an error.
-
retry
Re-subscribes to thisCompletable
if an error is emitted and the passedBiIntPredicate
returnstrue
.This method may result in a
This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:StackOverflowError
if 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 { resultOfThisCompletable(); } catch (Throwable cause) { if (shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1); } else { throw cause; } } }
- Parameters:
shouldRetry
-BiIntPredicate
that given the retry count and the most recentThrowable
emitted from thisCompletable
determines if the operation should be retried.- Returns:
- A
Completable
that completes with thisCompletable
or re-subscribes if an error is emitted and if the passedBiPredicate
returnedtrue
. - See Also:
-
retryWhen
Re-subscribes to thisCompletable
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully. If the returnedCompletable
emits an error, the returnedCompletable
terminates with that error.This method may result in a
This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:StackOverflowError
if 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 { resultOfThisCompletable(); } catch (Throwable cause) { try { shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally execute(attempts + 1); } catch (Throwable ignored) { throw cause; } } }
- Parameters:
retryWhen
-BiIntFunction
that given the retry count and the most recentThrowable
emitted from thisCompletable
returns aCompletable
. If thisCompletable
emits an error, that error is emitted from the returnedCompletable
, otherwise, originalCompletable
is re-subscribed when thisCompletable
completes.- Returns:
- A
Completable
that completes with thisCompletable
or re-subscribes if an error is emitted andCompletable
returned byBiFunction
completes successfully. - See Also:
-
repeat
Re-subscribes to thisCompletable
when it completes and the passedIntPredicate
returnstrue
.This method may result in a
This method provides a means to repeat an operation multiple times and in sequential programming is similar to:StackOverflowError
if 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())
int i = 0; do { resultOfThisCompletable(); } while (shouldRepeat.test(++i));
- Parameters:
shouldRepeat
-IntPredicate
that given the repeat count determines if the operation should be repeated- Returns:
- A
Publisher
that emits the value returned by the passedSupplier
everytime thisCompletable
completes. - See Also:
-
repeatWhen
Re-subscribes to thisCompletable
when it completes and theCompletable
returned by the suppliedIntFunction
completes successfully. If the returnedCompletable
emits an error, the returnedCompletable
emits an error.This method may result in a
This method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:StackOverflowError
if 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())
int i = 0; while (true) { resultOfThisCompletable(); try { repeatWhen.apply(++i); // Either throws or completes normally } catch (Throwable cause) { break; } }
- Parameters:
repeatWhen
-IntFunction
that given the repeat count returns aCompletable
. If thisCompletable
emits an error repeat is terminated, otherwise, originalCompletable
is re-subscribed when thisCompletable
completes.- Returns:
- A
Completable
that completes after all re-subscriptions completes. - See Also:
-
cache
Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
.In sequential programming this is similar to the following:
Void result = resultOfThisCompletable(); List<Void> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(result); } return multiResults;
- Returns:
- a
Completable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
. - See Also:
-
cache
Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
.In sequential programming this is similar to the following:
Void result = resultOfThisCompletable(); List<Void> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(result); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyCompletableSource.Subscriber
subscribe to the return value.- Returns:
- a
Completable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
. - See Also:
-
cache
Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
.In sequential programming this is similar to the following:
Void result = resultOfThisCompletable(); List<Void> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(result); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyCompletableSource.Subscriber
subscribe to the return value.cancelUpstream
-true
if upstream should becancelled
when all downstreamCompletableSource.Subscriber
s cancel.false
means that cancel will not be propagated upstream even if all downstreamCompletableSource.Subscriber
s cancel, and the upstream Subscription will stay valid until termination.- Returns:
- a
Completable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
. - See Also:
-
cache
public final Completable cache(int minSubscribers, boolean cancelUpstream, Function<Throwable, Completable> terminalResubscribe) Create aCompletable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
.In sequential programming this is similar to the following:
Void result = resultOfThisCompletable(); List<Void> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(result); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyCompletableSource.Subscriber
subscribe to the return value.cancelUpstream
-true
if upstream should becancelled
when all downstreamCompletableSource.Subscriber
s cancel.false
means that cancel will not be propagated upstream even if all downstreamCompletableSource.Subscriber
s cancel, and the upstream Subscription will stay valid until termination.terminalResubscribe
- AFunction
that is invoked when a terminal signal arrives from upstream, and returns aCompletable
whose termination resets the state of the returnedCompletable
and allows for downstream resubscribing. The argument to this function is as follows:null
if upstream terminates withCompletableSource.Subscriber.onComplete()
- otherwise the
Throwable
fromCompletableSource.Subscriber.onError(Throwable)
- Returns:
- a
Completable
that subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscriber
s. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber
. - See Also:
-
beforeOnSubscribe
Invokes theonSubscribe
Consumer
argument beforeCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.- Parameters:
onSubscribe
- Invoked beforeCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
beforeOnComplete
Invokes theonComplete
Runnable
argument beforeCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.From a sequential programming point of view this method is roughly equivalent to the following:
resultOfThisCompletable(); onComplete.run(); nextOperation();
- Parameters:
onComplete
- Invoked beforeCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
beforeOnError
Invokes theonError
Consumer
argument beforeCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.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); }
- Parameters:
onError
- Invoked beforeCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
beforeCancel
Invokes theonCancel
Runnable
argument beforeCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.- Parameters:
onCancel
- Invoked beforeCancellable.cancel()
is called for Subscriptions of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
beforeFinally
Invokes thewhenFinally
Runnable
argument before any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
.try { resultOfThisCompletable(); } finally { doFinally.run(); nextOperation(); // Maybe notifying of cancellation, or termination }
- Parameters:
doFinally
- Invoked before any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
. - See Also:
-
beforeFinally
Invokes the corresponding method onbeforeFinally
TerminalSignalConsumer
argument before any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
CompletableSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
.From a sequential programming point of view this method is roughly equivalent to the following:
try { resultOfThisCompletable(); } catch(Throwable t) { doFinally.onError(t); nextOperation(); // Maybe notifying of cancellation, or termination return; } doFinally.onComplete(); nextOperation(); // Maybe notifying of cancellation, or termination
- Parameters:
doFinally
- For each subscribe of the returnedCompletable
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Completable
. - See Also:
-
beforeSubscriber
public final Completable beforeSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all theCompletableSource.Subscriber
methods before theCompletableSource.Subscriber
s of the returnedCompletable
.- Parameters:
subscriberSupplier
- Creates a newCompletableSource.Subscriber
on each call to subscribe and invokes all theCompletableSource.Subscriber
methods before theCompletableSource.Subscriber
s of the returnedCompletable
.CompletableSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Completable
.
-
afterOnSubscribe
Invokes theonSubscribe
Consumer
argument afterCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.- Parameters:
onSubscribe
- Invoked afterCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
whenOnSubscribe
Invokes theonSubscribe
Consumer
argument whenCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.The order in which
onSubscribe
will be invoked relative toCompletableSource.Subscriber.onSubscribe(Cancellable)
is undefined. If you need strict ordering seebeforeOnSubscribe(Consumer)
andafterOnSubscribe(Consumer)
.- Parameters:
onSubscribe
- Invoked whenCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
. - See Also:
-
afterOnComplete
Invokes theonComplete
Runnable
argument afterCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.From a sequential programming point of view this method is roughly equivalent to the following:
resultOfThisCompletable(); nextOperation(); onComplete.run();
- Parameters:
onComplete
- Invoked afterCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
afterOnError
Invokes theonError
Consumer
argument afterCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.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); }
- Parameters:
onError
- Invoked afterCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
afterCancel
Invokes theonCancel
Runnable
argument afterCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.- Parameters:
onCancel
- Invoked afterCancellable.cancel()
is called for Subscriptions of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
.
-
afterFinally
Invokes thewhenFinally
Runnable
argument after any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
.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 doFinally.run(); }
- Parameters:
doFinally
- Invoked after any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
CompletableSource.Subscriber.onError(Throwable)
Cancellable.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
. MUST NOT throw.- Returns:
- The new
Completable
. - See Also:
-
afterFinally
Invokes the corresponding method onafterFinally
TerminalSignalConsumer
argument after any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
CompletableSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
CompletableSource.Subscriber
s of the returnedCompletable
.From a sequential programming point of view this method is roughly equivalent to the following:
try { resultOfThisCompletable(); } catch(Throwable t) { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onComplete();
- Parameters:
doFinally
- For each subscribe of the returnedCompletable
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Completable
. - See Also:
-
afterSubscriber
public final Completable afterSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all theCompletableSource.Subscriber
methods after theCompletableSource.Subscriber
s of the returnedCompletable
.- Parameters:
subscriberSupplier
- Creates a newCompletableSource.Subscriber
on each call to subscribe and invokes all theCompletableSource.Subscriber
methods after theCompletableSource.Subscriber
s of the returnedCompletable
.CompletableSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Completable
.
-
whenSubscriber
public final Completable whenSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes methods on thatCompletableSource.Subscriber
when the corresponding methods are called forCompletableSource.Subscriber
s of the returnedPublisher
.- Parameters:
subscriberSupplier
- Creates a newCompletableSource.Subscriber
for each new subscribe and invokes methods on thatCompletableSource.Subscriber
when the corresponding methods are called forCompletableSource.Subscriber
s of the returnedPublisher
.CompletableSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Completable
.
-
liftSync
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Completable
which will wrap theCompletableSource.Subscriber
using the providedoperator
argument before subscribing to thisCompletable
.
TheCompletable<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .afterFinally(..) // B
original -> modified
"operator" MUST be "synchronous" in that it does not interact with the originalCompletableSource.Subscriber
from outside the modifiedCompletableSource.Subscriber
orCancellable
threads. That is to say this operator will not impact theExecutor
constraints already in place between A and B above. If you need asynchronous behavior, or are unsure, seeliftAsync(CompletableOperator)
.- Parameters:
operator
- The custom operator logic. The input is the "original"CompletableSource.Subscriber
to thisCompletable
and the return is the "modified"CompletableSource.Subscriber
that provides custom operator business logic.- Returns:
- a
Completable
that when subscribed, theoperator
argument will be used to wrap theCompletableSource.Subscriber
before subscribing to thisCompletable
. - See Also:
-
liftAsync
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Completable
which will wrap theCompletableSource.Subscriber
using the providedoperator
argument before subscribing to thisCompletable
.
ThePublisher<X> pub = ...; pub.map(..) // A .liftAsync(original -> modified) .afterFinally(..) // B
original -> modified
"operator" MAY be "asynchronous" in that it may interact with the originalCompletableSource.Subscriber
from outside the modifiedCompletableSource.Subscriber
orCancellable
threads. More specifically:- all of the
CompletableSource.Subscriber
invocations going "downstream" (i.e. from A to B above) MAY be offloaded via anExecutor
- all of the
Cancellable
invocations going "upstream" (i.e. from B to A above) MAY be offloaded via anExecutor
- Parameters:
operator
- The custom operator logic. The input is the "original"CompletableSource.Subscriber
to thisCompletable
and the return is the "modified"CompletableSource.Subscriber
that provides custom operator business logic.- Returns:
- a
Completable
that when subscribed, theoperator
argument will be used to wrap theCompletableSource.Subscriber
before subscribing to thisCompletable
. - See Also:
- all of the
-
publishOn
Creates a newCompletable
that will use the passedExecutor
to invoke allCompletableSource.Subscriber
methods. This method does not override precedingExecutor
s, if any, specified forthis
Completable
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
publishOn(io.servicetalk.concurrent.Executor, BooleanSupplier)
, current operator always enforces offloading to the passedExecutor
.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke allCompletableSource.Subscriber
methods. - See Also:
-
publishOn
Creates a newCompletable
that may use the passedExecutor
to invoke allCompletableSource.Subscriber
methods. This method does not override precedingExecutor
s, if any, specified forthis
Completable
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
publishOn(io.servicetalk.concurrent.Executor)
, current operator may skip offloading to the passedExecutor
, depending on the result of theBooleanSupplier
hint.- Parameters:
executor
-Executor
to use.shouldOffload
- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalse
is returned in order to preserve signal ordering.- Returns:
- A new
Completable
that may use the passedExecutor
to invoke allCompletableSource.Subscriber
methods. - See Also:
-
subscribeOn
Creates a newCompletable
that will use the passedExecutor
to invoke the following methods:- All
Cancellable
methods. - The
handleSubscribe(CompletableSource.Subscriber)
method.
Executor
s, if any, specified forthis
Completable
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
subscribeOn(io.servicetalk.concurrent.Executor, BooleanSupplier)
, current operator always enforces offloading to the passedExecutor
.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke all methods ofCancellable
andhandleSubscribe(CompletableSource.Subscriber)
. - See Also:
- All
-
subscribeOn
Creates a newCompletable
that may use the passedExecutor
to invoke the following methods:- All
Cancellable
methods. - The
handleSubscribe(CompletableSource.Subscriber)
method.
Executor
s, if any, specified forthis
Completable
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
subscribeOn(io.servicetalk.concurrent.Executor)
, current operator may skip offloading to = the passedExecutor
, depending on the result of theBooleanSupplier
hint.- Parameters:
executor
-Executor
to use.shouldOffload
- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalse
is returned in order to preserve signal ordering.- Returns:
- A new
Completable
that may use the passedExecutor
to invoke all methods ofCancellable
andhandleSubscribe(CompletableSource.Subscriber)
. - See Also:
- All
-
setContextOnSubscribe
Specify theContextMap
to use forAsyncContext
when the returnedCompletable
is subscribed to.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.- Parameters:
context
- TheContextMap
to use forAsyncContext
when subscribed.- Returns:
- A
Completable
that will use theContextMap
forAsyncContext
when subscribed.
-
ambWith
Creates a newCompletable
that terminates with the result (either success or error) of either thisCompletable
or the passedother
Completable
, whichever terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated source will be cancelled.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 Completables here) // This is an approximation, this operator will pick the first result from either of the futures. return ft.get(); }
- Parameters:
other
-Completable
to subscribe to and race with thisCompletable
to propagate to the return value.- Returns:
- A new
Completable
that terminates with the result (either success or error) of either thisCompletable
or the passedother
Completable
, whichever terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. - See Also:
-
toPublisher
Converts thisCompletable
to aPublisher
.No
PublisherSource.Subscriber.onNext(Object)
signals will be delivered to the returnedPublisher
. Only terminal signals will be delivered. If you need more control you should consider usingconcat(Publisher)
.- Type Parameters:
T
- The value type of the resultingPublisher
.- Returns:
- A
Publisher
that mirrors the terminal signal from thisCompletable
.
-
toSingle
Converts thisCompletable
to aSingle
.- Returns:
- A
Single
that mirrors the terminal signal from thisCompletable
.
-
toCompletionStage
Converts thisCompletable
to aCompletionStage
.- Returns:
- A
CompletionStage
that mirrors the terminal signal from thisCompletable
.
-
toFuture
Converts thisCompletable
to aFuture
.- Returns:
- A
Future
that mirrors the terminal signal from thisCompletable
.
-
subscribeInternal
A internal subscribe method similar toCompletableSource.subscribe(Subscriber)
which can be used by different implementations to subscribe.- Parameters:
subscriber
-CompletableSource.Subscriber
to subscribe for the result.
-
subscribe
Subscribe to thisCompletable
and log anyCompletableSource.Subscriber.onError(Throwable)
.- Returns:
Cancellable
used to invokeCancellable.cancel()
on the parameter ofCompletableSource.Subscriber.onSubscribe(Cancellable)
for thisCompletable
.
-
subscribe
Subscribe to thisCompletable
and log anyCompletableSource.Subscriber.onError(Throwable)
. PassedRunnable
is invoked when thisCompletable
terminates successfully.- Parameters:
onComplete
-Runnable
to invoke when thisCompletable
terminates successfully.- Returns:
Cancellable
used to invokeCancellable.cancel()
on the parameter ofCompletableSource.Subscriber.onSubscribe(Cancellable)
for thisCompletable
.
-
subscribe
Subscribe to thisCompletable
, invoke passedRunnable
when thisCompletable
terminates successfully or emit an error toConsumer
when it fails.- Parameters:
onComplete
-Runnable
to invoke when thisCompletable
terminates successfully.errorConsumer
-Consumer
to accept the error when thisCompletable
fails.- Returns:
Cancellable
used to invokeCancellable.cancel()
on the parameter ofCompletableSource.Subscriber.onSubscribe(Cancellable)
for thisCompletable
.
-
handleSubscribe
Handles a subscriber to thisCompletable
.This method is invoked internally by
Completable
for every call to thesubscribeInternal(CompletableSource.Subscriber)
method.- Parameters:
subscriber
- the subscriber.
-
completed
Creates a realized completedCompletable
.- Returns:
- A new
Completable
.
-
fromRunnable
Creates aCompletable
which when subscribed will invokeRunnable.run()
on the passedRunnable
and emit the value returned by that invocation from the returnedCompletable
. Any error emitted by theRunnable
will terminate the returnedCompletable
with the same error.Blocking inside
Runnable.run()
will in turn block the subscribe call to the returnedCompletable
. If this behavior is undesirable then the returnedCompletable
should be offloaded usingsubscribeOn(io.servicetalk.concurrent.Executor)
which offloads the subscribe call.- Parameters:
runnable
-Runnable
which is invoked before completion.- Returns:
- A new
Completable
.
-
fromCallable
Creates aCompletable
which when subscribed will invokeCallable.call()
on the passedCallable
and emit the value returned by that invocation from the returnedCompletable
. Any error emitted by theCallable
will terminate the returnedCompletable
with the same error.Blocking inside
Callable.call()
will in turn block the subscribe call to the returnedCompletable
. If this behavior is undesirable then the returnedCompletable
should be offloaded usingsubscribeOn(io.servicetalk.concurrent.Executor)
which offloads the subscribe call.- Parameters:
callable
-Callable
which is invoked before completion.- Returns:
- A new
Completable
.
-
failed
Creates a realized failedCompletable
.- Parameters:
cause
- error that the returnedCompletable
completes with.- Returns:
- A new
Completable
.
-
never
Creates aCompletable
that never terminates.- Returns:
- A new
Completable
.
-
defer
Defer creation of aCompletable
till it is subscribed to.- Parameters:
completableSupplier
-Supplier
to create a newCompletable
for every call tosubscribeInternal(CompletableSource.Subscriber)
to the returnedCompletable
.- Returns:
- A new
Completable
that creates a newCompletable
usingcompletableFactory
for every call tosubscribeInternal(CompletableSource.Subscriber)
and forwards the termination signal from the newly createdCompletable
to itsCompletableSource.Subscriber
.
-
fromFuture
Convert from aFuture
to aCompletable
viaFuture.get()
.Note that because
Future
only presents blocking APIs to extract the result, so the process of getting the results will block. The caller ofsubscribeInternal(CompletableSource.Subscriber)
is responsible for offloading if necessary, and also offloading ifCancellable.cancel()
will be called if this operation may block.To apply a timeout see
timeout(long, TimeUnit)
and related methods.- Parameters:
future
- TheFuture
to convert.- Returns:
- A
Completable
that derives results fromFuture
. - See Also:
-
fromStage
Convert from aCompletionStage
to aCompletable
.A best effort is made to propagate
Cancellable.cancel()
to theCompletionStage
. Cancellation forCompletionStage
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 anExecutor
is appropriate.- Parameters:
stage
- TheCompletionStage
to convert.- Returns:
- A
Completable
that derives results fromCompletionStage
.
-
mergeAll
Returns aCompletable
that terminates when all the passedCompletable
terminate.This will actively subscribe to a default number of
Completable
s concurrently, in order to alter the defaults,mergeAll(Iterable, int)
.If any of the
Completable
s terminate with an error, returnedCompletable
will immediately terminate with that error. In such a case, any in-progressCompletable
s will be cancelled. In order to delay error termination usemergeAllDelayError(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(); }
- Parameters:
completables
-Iterable
ofCompletable
s, results of which are to be collected.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
mergeAll
Returns aCompletable
that terminates when all the passedCompletable
terminate.This will actively subscribe to a default number of
Completable
s concurrently, in order to alter the defaults,mergeAll(int, Completable...)
should be used.If any of the
Completable
s terminate with an error, returnedCompletable
will immediately terminate with that error. In such a case, any in-progressCompletable
s will be cancelled. In order to delay error termination usemergeAllDelayError(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(); }
- Parameters:
completables
-Completable
s, results of which are to be collected.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
mergeAll
public static Completable mergeAll(Iterable<? extends Completable> completables, int maxConcurrency) Returns aCompletable
that terminates when all the passedCompletable
terminate.If any of the
Completable
s terminate with an error, returnedCompletable
will immediately terminate with that error. In such a case, any in-progressCompletable
s will be cancelled. In order to delay error termination usemergeAllDelayError(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(); }
- Parameters:
completables
-Iterable
ofCompletable
s, results of which are to be collected.maxConcurrency
- Maximum number ofCompletable
s that will be active at any point in time.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
mergeAll
Returns aCompletable
that terminates when all the passedCompletable
terminate.If any of the
Completable
s terminate with an error, returnedCompletable
will immediately terminate with that error. In such a case, any in-progressCompletable
s will be cancelled. In order to delay error termination usemergeAllDelayError(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(); }
- Parameters:
maxConcurrency
- Maximum number ofCompletable
s that will be active at any point in time.completables
-Completable
s, results of which are to be collected.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
mergeAllDelayError
Returns aCompletable
that terminates when all the passedCompletable
terminate.This will actively subscribe to a default number of
Completable
s concurrently, in order to alter the defaults,mergeAllDelayError(Iterable, int)
should be used.If any of the
Completable
s terminate with an error, returnedCompletable
will wait for termination till all the otherCompletable
s have been subscribed and terminated. If it is expected for the returnedCompletable
to terminate on the first failingCompletable
,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);
- Parameters:
completables
-Iterable
ofCompletable
s, results of which are to be collected.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
mergeAllDelayError
Returns aCompletable
that terminates when all the passedCompletable
terminate.This will actively subscribe to a limited number of
Single
s concurrently, in order to alter the defaults,mergeAll(int, Completable...)
should be used.If any of the
Single
s terminate with an error, returnedSingle
will wait for termination till all the otherSingle
s have been subscribed and terminated. If it is expected for the returnedSingle
to terminate on the first failingSingle
,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);
- Parameters:
completables
-Completable
s, results of which are to be collected.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
mergeAllDelayError
public static Completable mergeAllDelayError(Iterable<? extends Completable> completables, int maxConcurrency) Returns aCompletable
that terminates when all the passedCompletable
terminate.If any of the
Single
s terminate with an error, returnedSingle
will wait for termination till all the otherSingle
s have been subscribed and terminated. If it is expected for the returnedSingle
to terminate on the first failingSingle
,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);
- Parameters:
completables
-Iterable
ofCompletable
s, results of which are to be collected.maxConcurrency
- Maximum number ofCompletable
s that will be active at any point in time.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
mergeAllDelayError
Returns aCompletable
that terminates when all the passedCompletable
terminate.If any of the
Single
s terminate with an error, returnedSingle
will wait for termination till all the otherSingle
s have been subscribed and terminated. If it is expected for the returnedSingle
to terminate on the first failingSingle
,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);
- Parameters:
maxConcurrency
- Maximum number ofCompletable
s that will be active at any point in time.completables
-Completable
s, results of which are to be collected.- Returns:
- A new
Completable
that terminates successfully if all the providedCompletable
s have terminated successfully or any one of them has terminated with a failure.
-
amb
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated sources will be cancelled.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 Completables here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }
- Parameters:
completables
-Completable
s to subscribe to and race to propagate to the return value.- Returns:
- A new
Completable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. - See Also:
-
amb
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. After the first source terminates, only the non-terminated sources will be cancelled.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 Completables here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }
- Parameters:
completables
-Completable
s to subscribe to and race to propagate to the return value.- Returns:
- A new
Completable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. - See Also:
-
anyOf
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated sources will be cancelled.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 Completables here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }
- Parameters:
completables
-Completable
s which to subscribe to and race to propagate to the return value.- Returns:
- A new
Completable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. - See Also:
-
anyOf
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. After the first source terminates, only the non-terminated sources will be cancelled.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 Completables here) // This is an approximation, this operator will pick the first result from any of the futures. return ft.get(); }
- Parameters:
completables
-Completable
s which to subscribe to and race to propagate to the return value.- Returns:
- A new
Completable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. that result. - See Also:
-