Class Completable
- java.lang.Object
-
- io.servicetalk.concurrent.api.Completable
-
- Direct Known Subclasses:
LegacyTestCompletable
,RunnableCompletable
,SubscribableCompletable
,TestCompletable
public abstract class Completable extends java.lang.Object
An asynchronous computation that does not emit any data. It just completes or emits an error.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 asource adapter
can be used to convert to aCompletableSource
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Completable()
New instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Completable
afterCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument afterCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.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
.Completable
afterFinally(java.lang.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
.Completable
afterOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument afterCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
afterOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument afterCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
afterOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
Invokes theonSubscribe
Consumer
argument afterCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
afterSubscriber(java.util.function.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(java.lang.Iterable<Completable> completables)
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.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(java.lang.Iterable<Completable> completables)
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.Completable
beforeCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument beforeCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.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
.Completable
beforeFinally(java.lang.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
.Completable
beforeOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument beforeCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
beforeOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument beforeCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
beforeOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
Invokes theonSubscribe
Consumer
argument beforeCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
beforeSubscriber(java.util.function.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
.static Completable
completed()
Creates a realized completedCompletable
.Completable
concat(Completable next)
Once thisCompletable
is terminated successfully, subscribe tonext
Completable
and propagate its terminal signal to the returnedCompletable
.<T> Publisher<T>
concat(Publisher<? extends T> next)
Once thisCompletable
is terminated successfully, subscribe tonext
Publisher
and propagate all emissions to the returnedPublisher
.<T> Single<T>
concat(Single<? extends T> next)
Once thisCompletable
is terminated successfully, subscribe tonext
Single
and propagate the result to the returnedSingle
.static Completable
defer(java.util.function.Supplier<? extends Completable> completableSupplier)
Defer creation of aCompletable
till it is subscribed to.static Completable
failed(java.lang.Throwable cause)
Creates a realized failedCompletable
.static Completable
fromFuture(java.util.concurrent.Future<?> future)
static Completable
fromRunnable(java.lang.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(java.util.concurrent.CompletionStage<?> stage)
Convert from aCompletionStage
to aCompletable
.protected abstract void
handleSubscribe(CompletableSource.Subscriber subscriber)
Handles a subscriber to thisCompletable
.Completable
idleTimeout(long duration, java.util.concurrent.TimeUnit unit)
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.Completable
idleTimeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.Completable
idleTimeout(java.time.Duration duration)
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.Completable
idleTimeout(java.time.Duration duration, Executor timeoutExecutor)
Creates a newCompletable
that will mimic the signals of thisCompletable
but will terminate with aTimeoutException
if timeduration
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 thisCompletable
with theother
Completable
so that the resultingCompletable
terminates successfully when both of these complete or either terminates with an error.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.<T> Publisher<T>
merge(Publisher<? extends T> mergeWith)
Merges the passedPublisher
with thisCompletable
.Completable
merge(java.lang.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(java.lang.Iterable<? extends Completable> completables)
Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAll(java.lang.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(java.lang.Iterable<? extends Completable> completables)
Returns aCompletable
that terminates when all the passedCompletable
terminate.static Completable
mergeAllDelayError(java.lang.Iterable<? extends Completable> completables, int maxConcurrency)
Returns aCompletable
that terminates when all the passedCompletable
terminate.Completable
mergeDelayError(Completable other)
Merges thisCompletable
with theother
Completable
, and delays error notification until all involvedCompletable
s terminate.Completable
mergeDelayError(Completable... other)
Merges thisCompletable
with theother
Completable
s, and delays error notification until all involvedCompletable
s terminate.Completable
mergeDelayError(java.lang.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.Completable
onErrorResume(java.util.function.Function<java.lang.Throwable,? extends Completable> nextFactory)
Recover from any error emitted by thisCompletable
by using anotherCompletable
provided by the passednextFactory
.Completable
publishAndSubscribeOn(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke the following methods: AllCompletableSource.Subscriber
methods. AllCancellable
methods. ThehandleSubscribe(CompletableSource.Subscriber)
method. This method does not override precedingExecutor
s, if any, specified forthis
Completable
.Completable
publishAndSubscribeOnOverride(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke the following methods: AllCompletableSource.Subscriber
methods. AllCancellable
methods. ThehandleSubscribe(CompletableSource.Subscriber)
method. This method overrides precedingExecutor
s, if any, specified forthis
Completable
.Completable
publishOn(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke allCompletableSource.Subscriber
methods.Completable
publishOnOverride(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke allCompletableSource.Subscriber
methods.Publisher<java.lang.Void>
repeat(java.util.function.IntPredicate shouldRepeat)
Publisher<java.lang.Void>
repeatWhen(java.util.function.IntFunction<? extends Completable> repeatWhen)
Re-subscribes to thisCompletable
when it completes and theCompletable
returned by the suppliedIntFunction
completes successfully.Completable
retry(BiIntPredicate<java.lang.Throwable> shouldRetry)
Re-subscribes to thisCompletable
if an error is emitted and the passedBiIntPredicate
returnstrue
.Completable
retryWhen(BiIntFunction<java.lang.Throwable,? extends Completable> retryWhen)
Re-subscribes to thisCompletable
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully.Cancellable
subscribe()
Subscribe to thisCompletable
and log anyCompletableSource.Subscriber.onError(Throwable)
.Cancellable
subscribe(java.lang.Runnable onComplete)
Subscribe to thisCompletable
and log anyCompletableSource.Subscriber.onError(Throwable)
.protected void
subscribeInternal(CompletableSource.Subscriber subscriber)
A internal subscribe method similar toCompletableSource.subscribe(Subscriber)
which can be used by different implementations to subscribe.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
.Completable
subscribeOnOverride(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke the following methods: AllCancellable
methods. ThehandleSubscribe(CompletableSource.Subscriber)
method. This method overrides precedingExecutor
s, if any, specified forthis
Completable
.Completable
subscribeShareContext()
Signifies that when the returnedCompletable
is subscribed to, theAsyncContext
will be shared instead of making acopy
.java.util.concurrent.CompletionStage<java.lang.Void>
toCompletionStage()
Converts thisCompletable
to aCompletionStage
.java.util.concurrent.Future<java.lang.Void>
toFuture()
Converts thisCompletable
to aFuture
.<T> Publisher<T>
toPublisher()
Converts thisCompletable
to aPublisher
.Single<java.lang.Void>
toSingle()
Converts thisCompletable
to aSingle
.Completable
whenCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument whenCancellable.cancel()
is called for Subscriptions of the returnedCompletable
.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
.Completable
whenFinally(java.lang.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
.Completable
whenOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument whenCompletableSource.Subscriber.onComplete()
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
whenOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument whenCompletableSource.Subscriber.onError(Throwable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
whenOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
Invokes theonSubscribe
Consumer
argument whenCompletableSource.Subscriber.onSubscribe(Cancellable)
is called forCompletableSource.Subscriber
s of the returnedCompletable
.Completable
whenSubscriber(java.util.function.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
.
-
-
-
Method Detail
-
onErrorResume
public final Completable onErrorResume(java.util.function.Function<java.lang.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
.
-
whenOnComplete
public final Completable whenOnComplete(java.lang.Runnable onComplete)
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:
beforeOnComplete(Runnable)
,afterOnComplete(Runnable)
-
whenOnError
public final Completable whenOnError(java.util.function.Consumer<java.lang.Throwable> onError)
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:
beforeOnError(Consumer)
,afterOnError(Consumer)
-
whenFinally
public final Completable whenFinally(java.lang.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()
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:
beforeFinally(Runnable)
,afterFinally(Runnable)
-
whenFinally
public 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()
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:
beforeFinally(TerminalSignalConsumer)
,afterFinally(TerminalSignalConsumer)
-
whenCancel
public final Completable whenCancel(java.lang.Runnable onCancel)
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:
beforeCancel(Runnable)
,afterCancel(Runnable)
-
idleTimeout
public final Completable idleTimeout(long duration, java.util.concurrent.TimeUnit unit)
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:
- ReactiveX timeout operator.
-
idleTimeout
public final Completable idleTimeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)
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:
- ReactiveX timeout operator.
-
idleTimeout
public final Completable idleTimeout(java.time.Duration duration)
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:
- ReactiveX timeout operator.
-
idleTimeout
public final Completable idleTimeout(java.time.Duration duration, Executor timeoutExecutor)
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:
- ReactiveX timeout operator.
-
concat
public final Completable concat(Completable next)
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
public final <T> Single<T> concat(Single<? extends T> next)
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
public final <T> Publisher<T> concat(Publisher<? extends T> next)
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
public 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.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
public 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.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
public final Completable merge(java.lang.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.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
public final <T> Publisher<T> merge(Publisher<? extends T> mergeWith)
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:
- ReactiveX merge operator.
-
mergeDelayError
public final Completable mergeDelayError(Completable other)
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
public final Completable mergeDelayError(Completable... other)
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
public final Completable mergeDelayError(java.lang.Iterable<? extends Completable> other)
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
public final Completable retry(BiIntPredicate<java.lang.Throwable> shouldRetry)
Re-subscribes to thisCompletable
if an error is emitted and the passedBiIntPredicate
returnstrue
.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; } } }
- 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:
- ReactiveX retry operator.
-
retryWhen
public final Completable retryWhen(BiIntFunction<java.lang.Throwable,? extends Completable> 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 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; } } }
- 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:
- ReactiveX retry operator.
-
repeat
public final Publisher<java.lang.Void> repeat(java.util.function.IntPredicate shouldRepeat)
Re-subscribes to thisCompletable
when it completes and the passedIntPredicate
returnstrue
.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));
- 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:
- ReactiveX repeat operator.
-
repeatWhen
public final Publisher<java.lang.Void> repeatWhen(java.util.function.IntFunction<? extends Completable> 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 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; } }
- 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:
- ReactiveX retry operator.
-
beforeOnSubscribe
public final Completable beforeOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
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
public final Completable beforeOnComplete(java.lang.Runnable onComplete)
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
public final Completable beforeOnError(java.util.function.Consumer<java.lang.Throwable> onError)
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
public final Completable beforeCancel(java.lang.Runnable onCancel)
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
public final Completable beforeFinally(java.lang.Runnable doFinally)
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:
- ReactiveX do operator.
-
beforeFinally
public 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()
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:
- ReactiveX do operator.
-
beforeSubscriber
public final Completable beforeSubscriber(java.util.function.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
public final Completable afterOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
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
public final Completable whenOnSubscribe(java.util.function.Consumer<Cancellable> onSubscribe)
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:
beforeOnSubscribe(Consumer)
,afterOnSubscribe(Consumer)
-
afterOnComplete
public final Completable afterOnComplete(java.lang.Runnable onComplete)
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
public final Completable afterOnError(java.util.function.Consumer<java.lang.Throwable> onError)
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
public final Completable afterCancel(java.lang.Runnable onCancel)
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
public final Completable afterFinally(java.lang.Runnable doFinally)
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:
- ReactiveX do operator.
-
afterFinally
public 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()
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:
- ReactiveX do operator.
-
afterSubscriber
public final Completable afterSubscriber(java.util.function.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(java.util.function.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
public final Completable liftSync(CompletableOperator operator)
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(CompletableOperator)
-
liftAsync
public final Completable liftAsync(CompletableOperator operator)
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:
liftSync(CompletableOperator)
- all of the
-
publishOn
public final Completable publishOn(Executor executor)
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
. If such an override is required,publishOnOverride(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke all methods on theCompletableSource.Subscriber
.
-
publishOnOverride
public final Completable publishOnOverride(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke allCompletableSource.Subscriber
methods. This method overrides precedingExecutor
s, if any, specified forthis
Completable
. That is to say preceding and subsequent operations for this execution chain will use thisExecutor
. If such an override is not required,publishOn(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke all methods ofCompletableSource.Subscriber
,Cancellable
andhandleSubscribe(CompletableSource.Subscriber)
both for the returnedCompletable
as well asthis
Completable
.
-
subscribeOn
public final Completable subscribeOn(Executor executor)
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
. If such an override is required,subscribeOnOverride(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke all methods ofCancellable
andhandleSubscribe(CompletableSource.Subscriber)
.
- All
-
subscribeOnOverride
public final Completable subscribeOnOverride(Executor executor)
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
. That is to say preceding and subsequent operations for this execution chain will use thisExecutor
. If such an override is not required,subscribeOn(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke all methods ofCancellable
andhandleSubscribe(CompletableSource.Subscriber)
both for the returnedCompletable
as well asthis
Completable
.
- All
-
publishAndSubscribeOn
public final Completable publishAndSubscribeOn(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke the following methods:- All
CompletableSource.Subscriber
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
. If such an override is required,publishAndSubscribeOnOverride(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke all methodsCompletableSource.Subscriber
,Cancellable
andhandleSubscribe(CompletableSource.Subscriber)
.
- All
-
publishAndSubscribeOnOverride
public final Completable publishAndSubscribeOnOverride(Executor executor)
Creates a newCompletable
that will use the passedExecutor
to invoke the following methods:- All
CompletableSource.Subscriber
methods. - All
Cancellable
methods. - The
handleSubscribe(CompletableSource.Subscriber)
method.
Executor
s, if any, specified forthis
Completable
. That is to say preceding and subsequent operations for this execution chain will use thisExecutor
. If such an override is not required,publishAndSubscribeOn(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Completable
that will use the passedExecutor
to invoke all methods ofCompletableSource.Subscriber
,Cancellable
andhandleSubscribe(CompletableSource.Subscriber)
both for the returnedCompletable
as well asthis
Completable
.
- All
-
subscribeShareContext
public final Completable subscribeShareContext()
Signifies that when the returnedCompletable
is subscribed to, theAsyncContext
will be shared instead of making acopy
.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.- Returns:
- A
Completable
that will share theAsyncContext
instead of making acopy
when subscribed to.
-
ambWith
public 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.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
with which the result of thisCompletable
is to be ambiguated.- Returns:
- A new
Completable
that terminates with the result (either success or error) of either thisCompletable
or the passedother
Completable
, whichever terminates first. - See Also:
- ReactiveX amb operator.
-
toPublisher
public final <T> Publisher<T> 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
public final Single<java.lang.Void> toSingle()
Converts thisCompletable
to aSingle
.- Returns:
- A
Single
that mirrors the terminal signal from thisCompletable
.
-
toCompletionStage
public final java.util.concurrent.CompletionStage<java.lang.Void> toCompletionStage()
Converts thisCompletable
to aCompletionStage
.- Returns:
- A
CompletionStage
that mirrors the terminal signal from thisCompletable
.
-
toFuture
public final java.util.concurrent.Future<java.lang.Void> toFuture()
Converts thisCompletable
to aFuture
.- Returns:
- A
Future
that mirrors the terminal signal from thisCompletable
.
-
subscribeInternal
protected final void subscribeInternal(CompletableSource.Subscriber subscriber)
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
public final Cancellable 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
public final Cancellable subscribe(java.lang.Runnable onComplete)
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
.
-
handleSubscribe
protected abstract void handleSubscribe(CompletableSource.Subscriber subscriber)
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
public static Completable completed()
Creates a realized completedCompletable
.- Returns:
- A new
Completable
.
-
fromRunnable
public static Completable fromRunnable(java.lang.Runnable runnable)
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 using one of the operators that offloads the subscribe call (eg:subscribeOn(Executor)
,publishAndSubscribeOn(Executor)
).- Parameters:
runnable
-Runnable
which is invoked before completion.- Returns:
- A new
Completable
.
-
failed
public static Completable failed(java.lang.Throwable cause)
Creates a realized failedCompletable
.- Parameters:
cause
- error that the returnedCompletable
completes with.- Returns:
- A new
Completable
.
-
never
public static Completable never()
Creates aCompletable
that never terminates.- Returns:
- A new
Completable
.
-
defer
public static Completable defer(java.util.function.Supplier<? extends Completable> completableSupplier)
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
public static Completable fromFuture(java.util.concurrent.Future<?> future)
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
idleTimeout(long, TimeUnit)
and related methods.- Parameters:
future
- TheFuture
to convert.- Returns:
- A
Completable
that derives results fromFuture
. - See Also:
idleTimeout(long, TimeUnit)
-
fromStage
public static Completable fromStage(java.util.concurrent.CompletionStage<?> stage)
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
public static Completable mergeAll(java.lang.Iterable<? extends Completable> completables)
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
public static Completable mergeAll(Completable... completables)
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(java.lang.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
public static Completable mergeAll(int maxConcurrency, Completable... completables)
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
public static Completable mergeAllDelayError(java.lang.Iterable<? extends Completable> completables)
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
public static Completable mergeAllDelayError(Completable... completables)
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(java.lang.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
public static Completable mergeAllDelayError(int maxConcurrency, Completable... completables)
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
public 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.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 the result of which are to be ambiguated.- Returns:
- A new
Completable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. - See Also:
- ReactiveX amb operator.
-
amb
public static Completable amb(java.lang.Iterable<Completable> completables)
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the 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 the result of which are to be ambiguated.- 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:
- ReactiveX amb operator.
-
anyOf
public 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.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 the result of which are to be ambiguated.- Returns:
- A new
Completable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first. - See Also:
- ReactiveX amb operator.
-
anyOf
public static Completable anyOf(java.lang.Iterable<Completable> completables)
Creates a newCompletable
that terminates with the result (either success or error) of whichever amongst the passedcompletables
that terminates first.From a sequential programming point of view this method is roughly equivalent to the following:
for (Future<T> ft: futures) { // Provided Futures (analogous to the 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 the result of which are to be ambiguated.- 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:
- ReactiveX amb operator.
-
-