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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal CompletableafterCancel(Runnable onCancel) Invokes theonCancelRunnableargument afterCancellable.cancel()is called for Subscriptions of the returnedCompletable.final CompletableafterFinally(TerminalSignalConsumer doFinally) Invokes the corresponding method onafterFinallyTerminalSignalConsumerargument 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.Subscribers of the returnedCompletable.final CompletableafterFinally(Runnable doFinally) Invokes thewhenFinallyRunnableargument after any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()for Subscriptions/CompletableSource.Subscribers of the returnedCompletable.final CompletableafterOnComplete(Runnable onComplete) Invokes theonCompleteRunnableargument afterCompletableSource.Subscriber.onComplete()is called forCompletableSource.Subscribers of the returnedCompletable.final CompletableafterOnError(Consumer<Throwable> onError) Invokes theonErrorConsumerargument afterCompletableSource.Subscriber.onError(Throwable)is called forCompletableSource.Subscribers of the returnedCompletable.final CompletableafterOnSubscribe(Consumer<Cancellable> onSubscribe) Invokes theonSubscribeConsumerargument afterCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable.final CompletableafterSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theCompletableSource.Subscribermethods after theCompletableSource.Subscribers of the returnedCompletable.static Completableamb(Completable... completables) Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first.static Completableamb(Iterable<Completable> completables) Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first.final CompletableambWith(Completable other) Creates a newCompletablethat terminates with the result (either success or error) of either thisCompletableor the passedotherCompletable, whichever terminates first.static CompletableanyOf(Completable... completables) Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first.static CompletableanyOf(Iterable<Completable> completables) Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first.final CompletablebeforeCancel(Runnable onCancel) Invokes theonCancelRunnableargument beforeCancellable.cancel()is called for Subscriptions of the returnedCompletable.final CompletablebeforeFinally(TerminalSignalConsumer doFinally) Invokes the corresponding method onbeforeFinallyTerminalSignalConsumerargument 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.Subscribers of the returnedCompletable.final CompletablebeforeFinally(Runnable doFinally) Invokes thewhenFinallyRunnableargument before any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()for Subscriptions/CompletableSource.Subscribers of the returnedCompletable.final CompletablebeforeOnComplete(Runnable onComplete) Invokes theonCompleteRunnableargument beforeCompletableSource.Subscriber.onComplete()is called forCompletableSource.Subscribers of the returnedCompletable.final CompletablebeforeOnError(Consumer<Throwable> onError) Invokes theonErrorConsumerargument beforeCompletableSource.Subscriber.onError(Throwable)is called forCompletableSource.Subscribers of the returnedCompletable.final CompletablebeforeOnSubscribe(Consumer<Cancellable> onSubscribe) Invokes theonSubscribeConsumerargument beforeCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable.final CompletablebeforeSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theCompletableSource.Subscribermethods before theCompletableSource.Subscribers of the returnedCompletable.final Completablecache()Create aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers.final Completablecache(int minSubscribers) Create aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers.final Completablecache(int minSubscribers, boolean cancelUpstream) Create aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers.final Completablecache(int minSubscribers, boolean cancelUpstream, Function<Throwable, Completable> terminalResubscribe) Create aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers.static CompletableCreates a realized completedCompletable.final Completableconcat(Completable next) Once thisCompletableis terminated successfully, subscribe tonextCompletableand propagate its terminal signal to the returnedCompletable.final Completableconcat(Completable... nexts) Once thisCompletableis terminated successfully, subscribe to eachCompletableinnextsin a sequential fashion after termination, and the final terminal signals is propagated to the returnedCompletable.final <T> Publisher<T>Once thisCompletableis terminated successfully, subscribe tonextPublisherand propagate all emissions to the returnedPublisher.final <T> Single<T>Once thisCompletableis terminated successfully, subscribe tonextSingleand propagate the result to the returnedSingle.static Completabledefer(Supplier<? extends Completable> completableSupplier) Defer creation of aCompletabletill it is subscribed to.static CompletableCreates a realized failedCompletable.static CompletablefromCallable(Callable<Void> callable) Creates aCompletablewhich when subscribed will invokeCallable.call()on the passedCallableand emit the value returned by that invocation from the returnedCompletable.static CompletablefromFuture(Future<?> future) static CompletablefromRunnable(Runnable runnable) Creates aCompletablewhich when subscribed will invokeRunnable.run()on the passedRunnableand emit the value returned by that invocation from the returnedCompletable.static CompletablefromStage(CompletionStage<?> stage) Convert from aCompletionStageto aCompletable.protected abstract voidhandleSubscribe(CompletableSource.Subscriber subscriber) Handles a subscriber to thisCompletable.final CompletableliftAsync(CompletableOperator operator) This method requires advanced knowledge of building operators.final CompletableliftSync(CompletableOperator operator) This method requires advanced knowledge of building operators.final Completablemerge(Completable other) Merges thisCompletablewith theotherCompletableso that the resultingCompletableterminates successfully when both of these complete or either terminates with an error.final Completablemerge(Completable... other) Merges thisCompletablewith theotherCompletables so that the resultingCompletableterminates successfully when all of these complete or any one terminates with an error.final <T> Publisher<T>Merges the passedPublisherwith thisCompletable.final Completablemerge(Iterable<? extends Completable> other) Merges thisCompletablewith theotherCompletables so that the resultingCompletableterminates successfully when all of these complete or terminates with an error when any one terminates with an error.static CompletablemergeAll(int maxConcurrency, Completable... completables) Returns aCompletablethat terminates when all the passedCompletableterminate.static CompletablemergeAll(Completable... completables) Returns aCompletablethat terminates when all the passedCompletableterminate.static CompletablemergeAll(Iterable<? extends Completable> completables) Returns aCompletablethat terminates when all the passedCompletableterminate.static CompletablemergeAll(Iterable<? extends Completable> completables, int maxConcurrency) Returns aCompletablethat terminates when all the passedCompletableterminate.static CompletablemergeAllDelayError(int maxConcurrency, Completable... completables) Returns aCompletablethat terminates when all the passedCompletableterminate.static CompletablemergeAllDelayError(Completable... completables) Returns aCompletablethat terminates when all the passedCompletableterminate.static CompletablemergeAllDelayError(Iterable<? extends Completable> completables) Returns aCompletablethat terminates when all the passedCompletableterminate.static CompletablemergeAllDelayError(Iterable<? extends Completable> completables, int maxConcurrency) Returns aCompletablethat terminates when all the passedCompletableterminate.final CompletablemergeDelayError(Completable other) Merges thisCompletablewith theotherCompletable, and delays error notification until all involvedCompletables terminate.final CompletablemergeDelayError(Completable... other) Merges thisCompletablewith theotherCompletables, and delays error notification until all involvedCompletables terminate.final <T> Publisher<T>mergeDelayError(Publisher<? extends T> mergeWith) Merges the passedPublisherwith thisCompletable.final CompletablemergeDelayError(Iterable<? extends Completable> other) Merges thisCompletablewith theotherCompletables, and delays error notification until all involvedCompletables terminate.static Completablenever()Creates aCompletablethat never terminates.final CompletableTransform errors emitted on thisCompletableinto aCompletableSource.Subscriber.onComplete()signal (e.g.final <E extends Throwable>
CompletableonErrorComplete(Class<E> type) Transform errors emitted on thisCompletablewhich matchtypeinto aCompletableSource.Subscriber.onComplete()signal (e.g.final CompletableonErrorComplete(Predicate<? super Throwable> predicate) Transform errors emitted on thisCompletablewhich matchpredicateinto aCompletableSource.Subscriber.onComplete()signal (e.g.final <E extends Throwable>
CompletableonErrorMap(Class<E> type, Function<? super E, ? extends Throwable> mapper) Transform errors emitted on thisCompletablewhich matchtypeinto a different error.final CompletableonErrorMap(Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisCompletableinto a different error.final CompletableonErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisCompletablewhich matchpredicateinto a different error.final <E extends Throwable>
CompletableonErrorResume(Class<E> type, Function<? super E, ? extends Completable> nextFactory) Recover from errors emitted by thisCompletablewhich matchtypeby using anotherCompletableprovided by the passednextFactory.final CompletableonErrorResume(Function<? super Throwable, ? extends Completable> nextFactory) Recover from any error emitted by thisCompletableby using anotherCompletableprovided by the passednextFactory.final CompletableonErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Completable> nextFactory) Recover from errors emitted by thisCompletablewhich matchpredicateby using anotherCompletableprovided by the passednextFactory.final CompletableCreates a newCompletablethat will use the passedExecutorto invoke allCompletableSource.Subscribermethods.final CompletablepublishOn(Executor executor, BooleanSupplier shouldOffload) Creates a newCompletablethat may use the passedExecutorto invoke allCompletableSource.Subscribermethods.repeat(IntPredicate shouldRepeat) repeatWhen(IntFunction<? extends Completable> repeatWhen) Re-subscribes to thisCompletablewhen it completes and theCompletablereturned by the suppliedIntFunctioncompletes successfully.final Completableretry(BiIntPredicate<Throwable> shouldRetry) Re-subscribes to thisCompletableif an error is emitted and the passedBiIntPredicatereturnstrue.final CompletableretryWhen(BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisCompletableif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully.final CompletablesetContextOnSubscribe(ContextMap context) Deprecated.requiring this operator is a sign that there is a problem in your operator chain.final CompletableSignifies that when the returnedCompletableis subscribed to, theAsyncContextwill be shared instead of making acopy.final CancellableSubscribe to thisCompletableand log anyCompletableSource.Subscriber.onError(Throwable).final CancellableSubscribe to thisCompletableand log anyCompletableSource.Subscriber.onError(Throwable).final CancellableSubscribe to thisCompletable, invoke passedRunnablewhen thisCompletableterminates successfully or emit an error toConsumerwhen it fails.protected final voidsubscribeInternal(CompletableSource.Subscriber subscriber) A internal subscribe method similar toCompletableSource.subscribe(Subscriber)which can be used by different implementations to subscribe.final CompletablesubscribeOn(Executor executor) Creates a newCompletablethat will use the passedExecutorto invoke the following methods: AllCancellablemethods. ThehandleSubscribe(CompletableSource.Subscriber)method. This method does not override precedingExecutors, if any, specified forthisCompletable.final CompletablesubscribeOn(Executor executor, BooleanSupplier shouldOffload) Creates a newCompletablethat may use the passedExecutorto invoke the following methods: AllCancellablemethods. ThehandleSubscribe(CompletableSource.Subscriber)method. This method does not override precedingExecutors, if any, specified forthisCompletable.final CompletableCreates a newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.final CompletableCreates a newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.final CompletableCreates a newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.final CompletableCreates a newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.final CompletionStage<Void>Converts thisCompletableto aCompletionStage.toFuture()Converts thisCompletableto aFuture.final <T> Publisher<T>Converts thisCompletableto aPublisher.toSingle()Converts thisCompletableto aSingle.final CompletablewhenCancel(Runnable onCancel) Invokes theonCancelRunnableargument whenCancellable.cancel()is called for Subscriptions of the returnedCompletable.final CompletablewhenFinally(TerminalSignalConsumer doFinally) Invokes the corresponding method onwhenFinallyTerminalSignalConsumerargument 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.Subscribers of the returnedCompletable.final CompletablewhenFinally(Runnable doFinally) Invokes thewhenFinallyRunnableargument exactly once, when any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()for Subscriptions/CompletableSource.Subscribers of the returnedCompletable.final CompletablewhenOnComplete(Runnable onComplete) Invokes theonCompleteRunnableargument whenCompletableSource.Subscriber.onComplete()is called forCompletableSource.Subscribers of the returnedCompletable.final CompletablewhenOnError(Consumer<Throwable> onError) Invokes theonErrorConsumerargument whenCompletableSource.Subscriber.onError(Throwable)is called forCompletableSource.Subscribers of the returnedCompletable.final CompletablewhenOnSubscribe(Consumer<Cancellable> onSubscribe) Invokes theonSubscribeConsumerargument whenCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable.final CompletablewhenSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes methods on thatCompletableSource.Subscriberwhen the corresponding methods are called forCompletableSource.Subscribers of the returnedPublisher.
-
Constructor Details
-
Completable
protected Completable()New instance.
-
-
Method Details
-
onErrorComplete
Transform errors emitted on thisCompletableinto 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
Completablewhich transform errors emitted on thisCompletableinto aCompletableSource.Subscriber.onComplete()signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisCompletablewhich matchtypeinto 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- TheThrowabletype.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.- Returns:
- A
Completablewhich transform errors emitted on thisCompletablewhich matchtypeinto aCompletableSource.Subscriber.onComplete()signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisCompletablewhich matchpredicateinto 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- returnstrueif theThrowableshould be transformed to anCompletableSource.Subscriber.onComplete()signal. Returnsfalseto propagate the error.- Returns:
- A
Completablewhich transform errors emitted on thisCompletablewhich matchpredicateinto aCompletableSource.Subscriber.onComplete()signal (e.g. swallows the error). - See Also:
-
onErrorMap
Transform errors emitted on thisCompletableinto 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
Completablewhich transform errors emitted on thisCompletableinto 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 thisCompletablewhich matchtypeinto 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 ofThrowableto transform.- Parameters:
type- TheThrowabletype 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
Completablewhich transform errors emitted on thisCompletableinto a different error. - See Also:
-
onErrorMap
public final Completable onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisCompletablewhich matchpredicateinto 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- returnstrueif theThrowableshould be transformed viamapper. Returnsfalseto propagate the original error.mapper- returns the error used to terminate the returnedCompletable.- Returns:
- A
Completablewhich transform errors emitted on thisCompletableinto a different error. - See Also:
-
onErrorResume
public final Completable onErrorResume(Function<? super Throwable, ? extends Completable> nextFactory) Recover from any error emitted by thisCompletableby using anotherCompletableprovided 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 thisCompletableemits an error.- Returns:
- A
Completablethat recovers from an error from thisCompletableby using anotherCompletableprovided 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 thisCompletablewhich matchtypeby using anotherCompletableprovided 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 ofThrowableto transform.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.nextFactory- Returns the nextCompletable, when thisCompletableemits an error.- Returns:
- A
Completablethat recovers from an error from thisPublisherby using anotherCompletableprovided 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 thisCompletablewhich matchpredicateby using anotherCompletableprovided 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- returnstrueif theThrowableshould be transformed vianextFactory. Returnsfalseto propagate the original error.nextFactory- Returns the nextCompletable, when thisCompletableemits an error.- Returns:
- A
Completablethat recovers from an error from thisCompletableby using anotherCompletableprovided by the passednextFactory. - See Also:
-
whenOnComplete
Invokes theonCompleteRunnableargument whenCompletableSource.Subscriber.onComplete()is called forCompletableSource.Subscribers of the returnedCompletable.The order in which
onCompletewill 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable. - See Also:
-
whenOnError
Invokes theonErrorConsumerargument whenCompletableSource.Subscriber.onError(Throwable)is called forCompletableSource.Subscribers of the returnedCompletable.The order in which
onErrorwill 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable. - See Also:
-
whenFinally
Invokes thewhenFinallyRunnableargument exactly once, when any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()
CompletableSource.Subscribers of the returnedCompletable.The order in which
whenFinallywill 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.Subscribers of the returnedCompletableMUST NOT throw.- Returns:
- The new
Completable. - See Also:
-
whenFinally
Invokes the corresponding method onwhenFinallyTerminalSignalConsumerargument 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.Subscribers of the returnedCompletable.The order in which
whenFinallywill 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 thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Completable. - See Also:
-
whenCancel
Invokes theonCancelRunnableargument whenCancellable.cancel()is called for Subscriptions of the returnedCompletable.The order in which
whenFinallywill 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 newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedCompletableis subscribed.In the event of timeout any
CancellablefromCompletableSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedCompletableSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete().unit- The units forduration.- Returns:
- a new
Completablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses beforeCompletableSource.Subscriber.onComplete(). - See Also:
-
timeout
Creates a newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedCompletableis subscribed.In the event of timeout any
CancellablefromCompletableSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedCompletableSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete().unit- The units forduration.timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Completablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses beforeCompletableSource.Subscriber.onComplete(). - See Also:
-
timeout
Creates a newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedCompletableis subscribed.In the event of timeout any
CancellablefromCompletableSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedCompletableSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete().- Returns:
- a new
Completablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses beforeCompletableSource.Subscriber.onComplete(). - See Also:
-
timeout
Creates a newCompletablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedCompletableis subscribed.In the event of timeout any
CancellablefromCompletableSource.Subscriber.onSubscribe(Cancellable)will becancelledand the associatedCompletableSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse beforeCompletableSource.Subscriber.onComplete().timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Completablethat will mimic the signals of thisCompletablebut will terminate with aTimeoutExceptionif timedurationelapses beforeCompletableSource.Subscriber.onComplete(). - See Also:
-
concat
Once thisCompletableis terminated successfully, subscribe tonextCompletableand propagate its terminal signal to the returnedCompletable. Any error from thisCompletableornextCompletableare 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-Completableto subscribe after thisCompletableterminates successfully.- Returns:
- A
Completablethat emits the terminal signal ofnextCompletable, after thisCompletablehas terminated successfully.
-
concat
Once thisCompletableis terminated successfully, subscribe to eachCompletableinnextsin a sequential fashion after termination, and the final terminal signals is propagated to the returnedCompletable. Any error from thisCompletableor fromnextsCompletableare 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-Completables to subscribe after thisCompletableterminates successfully.- Returns:
- A
Completablethat emits the terminal signal ofnextsCompletables, after thisCompletablehas terminated successfully.
-
concat
Once thisCompletableis terminated successfully, subscribe tonextSingleand propagate the result to the returnedSingle. Any error from thisCompletableornextSingleare 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-Singleto subscribe after thisCompletableterminates successfully.- Returns:
- A
Singlethat emits the result ofnextSingle, after thisCompletablehas terminated successfully.
-
concat
Once thisCompletableis terminated successfully, subscribe tonextPublisherand propagate all emissions to the returnedPublisher. Any error from thisCompletableornextPublisherare 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-Publisherto subscribe after thisCompletableterminates successfully.- Returns:
- A
Publisherthat emits all items emitted fromnextPublisher, after thisCompletablehas terminated successfully.
-
merge
Merges thisCompletablewith theotherCompletableso that the resultingCompletableterminates 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-Completables to merge.- Returns:
Completablethat terminates successfully when this andotherCompletables complete or terminates with an error when either terminates with an error.
-
merge
Merges thisCompletablewith theotherCompletables so that the resultingCompletableterminates 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-Completables to merge.- Returns:
Completablethat terminates successfully when this and allotherCompletables complete or terminates with an error when any one terminates with an error.
-
merge
Merges thisCompletablewith theotherCompletables so that the resultingCompletableterminates 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-Completables to merge.- Returns:
Completablethat terminates successfully when this and allotherCompletables complete or terminates with an error when any one terminates with an error.
-
merge
Merges the passedPublisherwith thisCompletable.The resulting
Publisheremits all items emitted by the passedPublisherand terminates successfully when both thisCompletableand the passedPublisherterminates successfully. It terminates with an error when any one of thisCompletableor passedPublisherterminates 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- thePublisherto merge in- Returns:
Publisherthat emits all items emitted by the passedPublisherand terminates successfully when both thisCompletableand the passedPublisherterminates successfully. It terminates with an error when any one of thisCompletableor passedPublisherterminates with an error.- See Also:
-
mergeDelayError
Merges the passedPublisherwith thisCompletable.The resulting
Publisheremits all items emitted by the passedPublisherand terminates when both thisCompletableand the passedPublisherterminate. 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- thePublisherto merge in- Returns:
Publisheremits all items emitted by the passedPublisherand terminates when both thisCompletableand the passedPublisherterminate. If either terminates with an error then the error will be propagated to the return value.- See Also:
-
mergeDelayError
Merges thisCompletablewith theotherCompletable, and delays error notification until all involvedCompletables 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-Completableto merge.- Returns:
Completablethat terminates afterthisCompletableandotherCompletable. If all involvedCompletables terminate successfully then the return value will terminate successfully. If anyCompletableterminates in an error, then the return value will also terminate in an error.
-
mergeDelayError
Merges thisCompletablewith theotherCompletables, and delays error notification until all involvedCompletables 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-Completables to merge.- Returns:
Completablethat terminates afterthisCompletableand allotherCompletables. If all involvedCompletables terminate successfully then the return value will terminate successfully. If anyCompletableterminates in an error, then the return value will also terminate in an error.
-
mergeDelayError
Merges thisCompletablewith theotherCompletables, and delays error notification until all involvedCompletables 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-Completables to merge.- Returns:
Completablethat terminates afterthisCompletableand allotherCompletables. If all involvedCompletables terminate successfully then the return value will terminate successfully. If anyCompletableterminates in an error, then the return value will also terminate in an error.
-
retry
Re-subscribes to thisCompletableif an error is emitted and the passedBiIntPredicatereturnstrue.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:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())public T execute() { return execute(0); } private T execute(int attempts) { try { resultOfThisCompletable(); } catch (Throwable cause) { if (shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1); } else { throw cause; } } }- Parameters:
shouldRetry-BiIntPredicatethat given the retry count and the most recentThrowableemitted from thisCompletabledetermines if the operation should be retried.- Returns:
- A
Completablethat completes with thisCompletableor re-subscribes if an error is emitted and if the passedBiPredicatereturnedtrue. - See Also:
-
retryWhen
Re-subscribes to thisCompletableif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully. If the returnedCompletableemits an error, the returnedCompletableterminates 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:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())public T execute() { return execute(0); } private T execute(int attempts) { try { 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-BiIntFunctionthat given the retry count and the most recentThrowableemitted from thisCompletablereturns aCompletable. If thisCompletableemits an error, that error is emitted from the returnedCompletable, otherwise, originalCompletableis re-subscribed when thisCompletablecompletes.- Returns:
- A
Completablethat completes with thisCompletableor re-subscribes if an error is emitted andCompletablereturned byBiFunctioncompletes successfully. - See Also:
-
repeat
Re-subscribes to thisCompletablewhen it completes and the passedIntPredicatereturnstrue.This method may result in a
This method provides a means to repeat an operation multiple times and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())int i = 0; do { resultOfThisCompletable(); } while (shouldRepeat.test(++i));- Parameters:
shouldRepeat-IntPredicatethat given the repeat count determines if the operation should be repeated- Returns:
- A
Publisherthat emits the value returned by the passedSuppliereverytime thisCompletablecompletes. - See Also:
-
repeatWhen
Re-subscribes to thisCompletablewhen it completes and theCompletablereturned by the suppliedIntFunctioncompletes successfully. If the returnedCompletableemits an error, the returnedCompletableemits 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:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())int i = 0; while (true) { resultOfThisCompletable(); try { repeatWhen.apply(++i); // Either throws or completes normally } catch (Throwable cause) { break; } }- Parameters:
repeatWhen-IntFunctionthat given the repeat count returns aCompletable. If thisCompletableemits an error repeat is terminated, otherwise, originalCompletableis re-subscribed when thisCompletablecompletes.- Returns:
- A
Completablethat completes after all re-subscriptions completes. - See Also:
-
cache
Create aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. 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
Completablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber. - See Also:
-
cache
Create aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. 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.Subscribersubscribe to the return value.- Returns:
- a
Completablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber. - See Also:
-
cache
Create aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. 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.Subscribersubscribe to the return value.cancelUpstream-trueif upstream should becancelledwhen all downstreamCompletableSource.Subscribers cancel.falsemeans that cancel will not be propagated upstream even if all downstreamCompletableSource.Subscribers cancel, and the upstream Subscription will stay valid until termination.- Returns:
- a
Completablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. 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 aCompletablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. 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.Subscribersubscribe to the return value.cancelUpstream-trueif upstream should becancelledwhen all downstreamCompletableSource.Subscribers cancel.falsemeans that cancel will not be propagated upstream even if all downstreamCompletableSource.Subscribers cancel, and the upstream Subscription will stay valid until termination.terminalResubscribe- AFunctionthat is invoked when a terminal signal arrives from upstream, and returns aCompletablewhose termination resets the state of the returnedCompletableand allows for downstream resubscribing. The argument to this function is as follows:nullif upstream terminates withCompletableSource.Subscriber.onComplete()- otherwise the
ThrowablefromCompletableSource.Subscriber.onError(Throwable)
- Returns:
- a
Completablethat subscribes a single time upstream but allows for multiple downstreamCompletableSource.Subscribers. The terminal signal will be cached and delivered to each downstreamCompletableSource.Subscriber. - See Also:
-
beforeOnSubscribe
Invokes theonSubscribeConsumerargument beforeCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable.- Parameters:
onSubscribe- Invoked beforeCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable.
-
beforeOnComplete
Invokes theonCompleteRunnableargument beforeCompletableSource.Subscriber.onComplete()is called forCompletableSource.Subscribers 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable.
-
beforeOnError
Invokes theonErrorConsumerargument beforeCompletableSource.Subscriber.onError(Throwable)is called forCompletableSource.Subscribers 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable.
-
beforeCancel
Invokes theonCancelRunnableargument 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 thewhenFinallyRunnableargument before any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()
CompletableSource.Subscribers 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable. - See Also:
-
beforeFinally
Invokes the corresponding method onbeforeFinallyTerminalSignalConsumerargument 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.Subscribers 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 thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Completable. - See Also:
-
beforeSubscriber
public final Completable beforeSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theCompletableSource.Subscribermethods before theCompletableSource.Subscribers of the returnedCompletable.- Parameters:
subscriberSupplier- Creates a newCompletableSource.Subscriberon each call to subscribe and invokes all theCompletableSource.Subscribermethods before theCompletableSource.Subscribers of the returnedCompletable.CompletableSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Completable.
-
afterOnSubscribe
Invokes theonSubscribeConsumerargument afterCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable.- Parameters:
onSubscribe- Invoked afterCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable.
-
whenOnSubscribe
Invokes theonSubscribeConsumerargument whenCompletableSource.Subscriber.onSubscribe(Cancellable)is called forCompletableSource.Subscribers of the returnedCompletable.The order in which
onSubscribewill 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable. - See Also:
-
afterOnComplete
Invokes theonCompleteRunnableargument afterCompletableSource.Subscriber.onComplete()is called forCompletableSource.Subscribers 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable.
-
afterOnError
Invokes theonErrorConsumerargument afterCompletableSource.Subscriber.onError(Throwable)is called forCompletableSource.Subscribers 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable.
-
afterCancel
Invokes theonCancelRunnableargument 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 thewhenFinallyRunnableargument after any of the following terminal methods are called:CompletableSource.Subscriber.onComplete()CompletableSource.Subscriber.onError(Throwable)Cancellable.cancel()
CompletableSource.Subscribers 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.Subscribers of the returnedCompletable. MUST NOT throw.- Returns:
- The new
Completable. - See Also:
-
afterFinally
Invokes the corresponding method onafterFinallyTerminalSignalConsumerargument 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.Subscribers 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 thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Completable. - See Also:
-
afterSubscriber
public final Completable afterSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all theCompletableSource.Subscribermethods after theCompletableSource.Subscribers of the returnedCompletable.- Parameters:
subscriberSupplier- Creates a newCompletableSource.Subscriberon each call to subscribe and invokes all theCompletableSource.Subscribermethods after theCompletableSource.Subscribers of the returnedCompletable.CompletableSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Completable.
-
whenSubscriber
public final Completable whenSubscriber(Supplier<? extends CompletableSource.Subscriber> subscriberSupplier) Creates a newCompletableSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes methods on thatCompletableSource.Subscriberwhen the corresponding methods are called forCompletableSource.Subscribers of the returnedPublisher.- Parameters:
subscriberSupplier- Creates a newCompletableSource.Subscriberfor each new subscribe and invokes methods on thatCompletableSource.Subscriberwhen the corresponding methods are called forCompletableSource.Subscribers of the returnedPublisher.CompletableSource.Subscribermethods 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
Completablewhich will wrap theCompletableSource.Subscriberusing the providedoperatorargument before subscribing to thisCompletable.
TheCompletable<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .afterFinally(..) // Boriginal -> modified"operator" MUST be "synchronous" in that it does not interact with the originalCompletableSource.Subscriberfrom outside the modifiedCompletableSource.SubscriberorCancellablethreads. That is to say this operator will not impact theExecutorconstraints 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.Subscriberto thisCompletableand the return is the "modified"CompletableSource.Subscriberthat provides custom operator business logic.- Returns:
- a
Completablethat when subscribed, theoperatorargument will be used to wrap theCompletableSource.Subscriberbefore 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
Completablewhich will wrap theCompletableSource.Subscriberusing the providedoperatorargument before subscribing to thisCompletable.
ThePublisher<X> pub = ...; pub.map(..) // A .liftAsync(original -> modified) .afterFinally(..) // Boriginal -> modified"operator" MAY be "asynchronous" in that it may interact with the originalCompletableSource.Subscriberfrom outside the modifiedCompletableSource.SubscriberorCancellablethreads. More specifically:- all of the
CompletableSource.Subscriberinvocations going "downstream" (i.e. from A to B above) MAY be offloaded via anExecutor - all of the
Cancellableinvocations 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.Subscriberto thisCompletableand the return is the "modified"CompletableSource.Subscriberthat provides custom operator business logic.- Returns:
- a
Completablethat when subscribed, theoperatorargument will be used to wrap theCompletableSource.Subscriberbefore subscribing to thisCompletable. - See Also:
- all of the
-
publishOn
Creates a newCompletablethat will use the passedExecutorto invoke allCompletableSource.Subscribermethods. This method does not override precedingExecutors, if any, specified forthisCompletable. 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-Executorto use.- Returns:
- A new
Completablethat will use the passedExecutorto invoke allCompletableSource.Subscribermethods. - See Also:
-
publishOn
Creates a newCompletablethat may use the passedExecutorto invoke allCompletableSource.Subscribermethods. This method does not override precedingExecutors, if any, specified forthisCompletable. 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 theBooleanSupplierhint.- Parameters:
executor-Executorto use.shouldOffload- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalseis returned in order to preserve signal ordering.- Returns:
- A new
Completablethat may use the passedExecutorto invoke allCompletableSource.Subscribermethods. - See Also:
-
subscribeOn
Creates a newCompletablethat will use the passedExecutorto invoke the following methods:- All
Cancellablemethods. - The
handleSubscribe(CompletableSource.Subscriber)method.
Executors, if any, specified forthisCompletable. 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-Executorto use.- Returns:
- A new
Completablethat will use the passedExecutorto invoke all methods ofCancellableandhandleSubscribe(CompletableSource.Subscriber). - See Also:
- All
-
subscribeOn
Creates a newCompletablethat may use the passedExecutorto invoke the following methods:- All
Cancellablemethods. - The
handleSubscribe(CompletableSource.Subscriber)method.
Executors, if any, specified forthisCompletable. 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 theBooleanSupplierhint.- Parameters:
executor-Executorto use.shouldOffload- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalseis returned in order to preserve signal ordering.- Returns:
- A new
Completablethat may use the passedExecutorto invoke all methods ofCancellableandhandleSubscribe(CompletableSource.Subscriber). - See Also:
- All
-
setContextOnSubscribe
Deprecated.requiring this operator is a sign that there is a problem in your operator chain. Usedefer(Supplier)andshareContextOnSubscribe()to control context.Specify theContextMapto use forAsyncContextwhen the returnedCompletableis subscribed to.This operator only impacts behavior if the returned
Completableis subscribed directly after this operator, that means this must be the "last operator" in the chain for this to have an impact.- Parameters:
context- TheContextMapto use forAsyncContextwhen subscribed.- Returns:
- A
Completablethat will use theContextMapforAsyncContextwhen subscribed.
-
ambWith
Creates a newCompletablethat terminates with the result (either success or error) of either thisCompletableor the passedotherCompletable, 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-Completableto subscribe to and race with thisCompletableto propagate to the return value.- Returns:
- A new
Completablethat terminates with the result (either success or error) of either thisCompletableor the passedotherCompletable, whichever terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. - See Also:
-
toPublisher
Converts thisCompletableto 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
Publisherthat mirrors the terminal signal from thisCompletable.
-
toSingle
Converts thisCompletableto aSingle.- Returns:
- A
Singlethat mirrors the terminal signal from thisCompletable.
-
toCompletionStage
Converts thisCompletableto aCompletionStage.- Returns:
- A
CompletionStagethat mirrors the terminal signal from thisCompletable.
-
toFuture
Converts thisCompletableto aFuture.- Returns:
- A
Futurethat 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.Subscriberto subscribe for the result.
-
subscribe
Subscribe to thisCompletableand log anyCompletableSource.Subscriber.onError(Throwable).- Returns:
Cancellableused to invokeCancellable.cancel()on the parameter ofCompletableSource.Subscriber.onSubscribe(Cancellable)for thisCompletable.
-
subscribe
Subscribe to thisCompletableand log anyCompletableSource.Subscriber.onError(Throwable). PassedRunnableis invoked when thisCompletableterminates successfully.- Parameters:
onComplete-Runnableto invoke when thisCompletableterminates successfully.- Returns:
Cancellableused to invokeCancellable.cancel()on the parameter ofCompletableSource.Subscriber.onSubscribe(Cancellable)for thisCompletable.
-
subscribe
Subscribe to thisCompletable, invoke passedRunnablewhen thisCompletableterminates successfully or emit an error toConsumerwhen it fails.- Parameters:
onComplete-Runnableto invoke when thisCompletableterminates successfully.errorConsumer-Consumerto accept the error when thisCompletablefails.- Returns:
Cancellableused to invokeCancellable.cancel()on the parameter ofCompletableSource.Subscriber.onSubscribe(Cancellable)for thisCompletable.
-
handleSubscribe
Handles a subscriber to thisCompletable.This method is invoked internally by
Completablefor every call to thesubscribeInternal(CompletableSource.Subscriber)method.- Parameters:
subscriber- the subscriber.
-
completed
Creates a realized completedCompletable.- Returns:
- A new
Completable.
-
fromRunnable
Creates aCompletablewhich when subscribed will invokeRunnable.run()on the passedRunnableand emit the value returned by that invocation from the returnedCompletable. Any error emitted by theRunnablewill terminate the returnedCompletablewith the same error.Blocking inside
Runnable.run()will in turn block the subscribe call to the returnedCompletable. If this behavior is undesirable then the returnedCompletableshould be offloaded usingsubscribeOn(io.servicetalk.concurrent.Executor)which offloads the subscribe call.- Parameters:
runnable-Runnablewhich is invoked before completion.- Returns:
- A new
Completable.
-
fromCallable
Creates aCompletablewhich when subscribed will invokeCallable.call()on the passedCallableand emit the value returned by that invocation from the returnedCompletable. Any error emitted by theCallablewill terminate the returnedCompletablewith the same error.Blocking inside
Callable.call()will in turn block the subscribe call to the returnedCompletable. If this behavior is undesirable then the returnedCompletableshould be offloaded usingsubscribeOn(io.servicetalk.concurrent.Executor)which offloads the subscribe call.- Parameters:
callable-Callablewhich is invoked before completion.- Returns:
- A new
Completable.
-
failed
Creates a realized failedCompletable.- Parameters:
cause- error that the returnedCompletablecompletes with.- Returns:
- A new
Completable.
-
never
Creates aCompletablethat never terminates.- Returns:
- A new
Completable.
-
defer
Defer creation of aCompletabletill it is subscribed to.- Parameters:
completableSupplier-Supplierto create a newCompletablefor every call tosubscribeInternal(CompletableSource.Subscriber)to the returnedCompletable.- Returns:
- A new
Completablethat creates a newCompletableusingcompletableFactoryfor every call tosubscribeInternal(CompletableSource.Subscriber)and forwards the termination signal from the newly createdCompletableto itsCompletableSource.Subscriber.
-
fromFuture
Convert from aFutureto aCompletableviaFuture.get().Note that because
Futureonly 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- TheFutureto convert.- Returns:
- A
Completablethat derives results fromFuture. - See Also:
-
fromStage
Convert from aCompletionStageto aCompletable.A best effort is made to propagate
Cancellable.cancel()to theCompletionStage. Cancellation forCompletionStageimplementations 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 anExecutoris appropriate.- Parameters:
stage- TheCompletionStageto convert.- Returns:
- A
Completablethat derives results fromCompletionStage.
-
mergeAll
Returns aCompletablethat terminates when all the passedCompletableterminate.This will actively subscribe to a default number of
Completables concurrently, in order to alter the defaults,mergeAll(Iterable, int).If any of the
Completables terminate with an error, returnedCompletablewill immediately terminate with that error. In such a case, any in-progressCompletables 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-IterableofCompletables, results of which are to be collected.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables have terminated successfully or any one of them has terminated with a failure.
-
mergeAll
Returns aCompletablethat terminates when all the passedCompletableterminate.This will actively subscribe to a default number of
Completables concurrently, in order to alter the defaults,mergeAll(int, Completable...)should be used.If any of the
Completables terminate with an error, returnedCompletablewill immediately terminate with that error. In such a case, any in-progressCompletables 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-Completables, results of which are to be collected.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables 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 aCompletablethat terminates when all the passedCompletableterminate.If any of the
Completables terminate with an error, returnedCompletablewill immediately terminate with that error. In such a case, any in-progressCompletables 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-IterableofCompletables, results of which are to be collected.maxConcurrency- Maximum number ofCompletables that will be active at any point in time.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables have terminated successfully or any one of them has terminated with a failure.
-
mergeAll
Returns aCompletablethat terminates when all the passedCompletableterminate.If any of the
Completables terminate with an error, returnedCompletablewill immediately terminate with that error. In such a case, any in-progressCompletables 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 ofCompletables that will be active at any point in time.completables-Completables, results of which are to be collected.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables have terminated successfully or any one of them has terminated with a failure.
-
mergeAllDelayError
Returns aCompletablethat terminates when all the passedCompletableterminate.This will actively subscribe to a default number of
Completables concurrently, in order to alter the defaults,mergeAllDelayError(Iterable, int)should be used.If any of the
Completables terminate with an error, returnedCompletablewill wait for termination till all the otherCompletables have been subscribed and terminated. If it is expected for the returnedCompletableto 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-IterableofCompletables, results of which are to be collected.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables have terminated successfully or any one of them has terminated with a failure.
-
mergeAllDelayError
Returns aCompletablethat terminates when all the passedCompletableterminate.This will actively subscribe to a limited number of
Singles concurrently, in order to alter the defaults,mergeAll(int, Completable...)should be used.If any of the
Singles terminate with an error, returnedSinglewill wait for termination till all the otherSingles have been subscribed and terminated. If it is expected for the returnedSingleto 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-Completables, results of which are to be collected.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables 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 aCompletablethat terminates when all the passedCompletableterminate.If any of the
Singles terminate with an error, returnedSinglewill wait for termination till all the otherSingles have been subscribed and terminated. If it is expected for the returnedSingleto 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-IterableofCompletables, results of which are to be collected.maxConcurrency- Maximum number ofCompletables that will be active at any point in time.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables have terminated successfully or any one of them has terminated with a failure.
-
mergeAllDelayError
Returns aCompletablethat terminates when all the passedCompletableterminate.If any of the
Singles terminate with an error, returnedSinglewill wait for termination till all the otherSingles have been subscribed and terminated. If it is expected for the returnedSingleto 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 ofCompletables that will be active at any point in time.completables-Completables, results of which are to be collected.- Returns:
- A new
Completablethat terminates successfully if all the providedCompletables have terminated successfully or any one of them has terminated with a failure.
-
amb
Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat 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-Completables to subscribe to and race to propagate to the return value.- Returns:
- A new
Completablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. - See Also:
-
amb
Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat 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-Completables to subscribe to and race to propagate to the return value.- Returns:
- A new
Completablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first. Therefore, the result is said to be ambiguous relative to which source it originated from. - See Also:
-
anyOf
Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat 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-Completables which to subscribe to and race to propagate to the return value.- Returns:
- A new
Completablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first. - See Also:
-
anyOf
Creates a newCompletablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat 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-Completables which to subscribe to and race to propagate to the return value.- Returns:
- A new
Completablethat terminates with the result (either success or error) of whichever amongst the passedcompletablesthat terminates first. that result. - See Also:
-