CompletableFuture
open class CompletableFuture<T : Any!> : CompletionStage<T>, Future<T>
| kotlin.Any | |
| ↳ | java.util.concurrent.CompletableFuture |
A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion.
When two or more threads attempt to complete, completeExceptionally, or cancel a CompletableFuture, only one of them succeeds.
In addition to these and related methods for directly manipulating status and results, CompletableFuture implements interface CompletionStage with the following policies:
- Actions supplied for dependent completions of non-async methods may be performed by the thread that completes the current CompletableFuture, or by any other caller of a completion method.
- All async methods without an explicit Executor argument are performed using the
ForkJoinPool.commonPool()(unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run each task). To simplify monitoring, debugging, and tracking, all generated asynchronous tasks are instances of the marker interfaceAsynchronousCompletionTask. Operations with time-delays can use adapter methods defined in this class, for example:supplyAsync(supplier, delayedExecutor(timeout, timeUnit)). To support methods with delays and timeouts, this class maintains at most one daemon thread for triggering and cancelling actions, not for running them. - All CompletionStage methods are implemented independently of other public methods, so the behavior of one method is not impacted by overrides of others in subclasses.
CompletableFuture also implements Future with the following policies:
- Since (unlike
FutureTask) this class has no direct control over the computation that causes it to be completed, cancellation is treated as just another form of exceptional completion. Methodcancelhas the same effect ascompleteExceptionally(new CancellationException()). MethodisCompletedExceptionallycan be used to determine if a CompletableFuture completed in any exceptional fashion. - In case of exceptional completion with a CompletionException, methods
get()andget(long,java.util.concurrent.TimeUnit)throw anExecutionExceptionwith the same cause as held in the corresponding CompletionException. To simplify usage in most contexts, this class also defines methodsjoin()andgetNowthat instead throw the CompletionException directly in these cases.
Arguments used to pass a completion result (that is, for parameters of type T) for methods accepting them may be null, but passing a null value for any other parameter will result in a NullPointerException being thrown.
Summary
| Nested classes | |
|---|---|
| abstract |
A marker interface identifying asynchronous tasks produced by |
| Public constructors | |
|---|---|
|
Creates a new incomplete CompletableFuture. |
|
| Public methods | |
|---|---|
| open CompletableFuture<Void!>! |
acceptEither(other: CompletionStage<out T>!, action: Consumer<in T>!)Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action. |
| open CompletableFuture<Void!>! |
acceptEitherAsync(other: CompletionStage<out T>!, action: Consumer<in T>!)Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied action. |
| open CompletableFuture<Void!>! |
acceptEitherAsync(other: CompletionStage<out T>!, action: Consumer<in T>!, executor: Executor!)Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action. |
| open static CompletableFuture<Void!>! |
allOf(vararg cfs: CompletableFuture<*>!)Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete. |
| open static CompletableFuture<Any!>! |
anyOf(vararg cfs: CompletableFuture<*>!)Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result. |
| open CompletableFuture<U>! |
applyToEither(other: CompletionStage<out T>!, fn: Function<in T, U>!)Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function. |
| open CompletableFuture<U>! |
applyToEitherAsync(other: CompletionStage<out T>!, fn: Function<in T, U>!)Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied function. |
| open CompletableFuture<U>! |
applyToEitherAsync(other: CompletionStage<out T>!, fn: Function<in T, U>!, executor: Executor!)Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function. |
| open Boolean |
If not already completed, completes this CompletableFuture with a |
| open Boolean |
complete(value: T)If not already completed, sets the value returned by |
| open CompletableFuture<T>! |
completeAsync(supplier: Supplier<out T>!)Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the default executor. |
| open CompletableFuture<T>! |
completeAsync(supplier: Supplier<out T>!, executor: Executor!)Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the given executor. |
| open Boolean |
If not already completed, causes invocations of |
| open CompletableFuture<T>! |
completeOnTimeout(value: T, timeout: Long, unit: TimeUnit!)Completes this CompletableFuture with the given value if not otherwise completed before the given timeout. |
| open static CompletableFuture<U>! |
completedFuture(value: U)Returns a new CompletableFuture that is already completed with the given value. |
| open static CompletionStage<U>! |
completedStage(value: U)Returns a new CompletionStage that is already completed with the given value and supports only those methods in interface |
| open CompletableFuture<T>! |
copy()Returns a new CompletableFuture that is completed normally with the same value as this CompletableFuture when it completes normally. |
| open Executor! |
Returns the default Executor used for async methods that do not specify an Executor. |
| open static Executor! |
delayedExecutor(delay: Long, unit: TimeUnit!)Returns a new Executor that submits a task to the default executor after the given delay (or no delay if non-positive). |
| open static Executor! |
delayedExecutor(delay: Long, unit: TimeUnit!, executor: Executor!)Returns a new Executor that submits a task to the given base executor after the given delay (or no delay if non-positive). |
| open Throwable! |
Returns the exception thrown by the task, without waiting. |
| open CompletableFuture<T>! |
exceptionally(fn: Function<Throwable!, out T>!)Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function. |
| open CompletableFuture<T>! |
exceptionallyAsync(fn: Function<Throwable!, out T>!)Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, using this stage's default asynchronous execution facility. |
| open CompletableFuture<T>! |
exceptionallyAsync(fn: Function<Throwable!, out T>!, executor: Executor!)Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, using the supplied Executor. |
| open CompletableFuture<T>! |
exceptionallyCompose(fn: Function<Throwable!, out CompletionStage<T>!>!)Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception. |
| open CompletableFuture<T>! |
exceptionallyComposeAsync(fn: Function<Throwable!, out CompletionStage<T>!>!)Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, using this stage's default asynchronous execution facility. |
| open CompletableFuture<T>! |
exceptionallyComposeAsync(fn: Function<Throwable!, out CompletionStage<T>!>!, executor: Executor!)Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, using the supplied Executor. |
| open static CompletableFuture<U>! |
failedFuture(ex: Throwable!)Returns a new CompletableFuture that is already completed exceptionally with the given exception. |
| open static CompletionStage<U>! |
failedStage(ex: Throwable!)Returns a new CompletionStage that is already completed exceptionally with the given exception and supports only those methods in interface |
| open T |
get()Waits if necessary for this future to complete, and then returns its result. |
| open T |
Waits if necessary for at most the given time for this future to complete, and then returns its result, if available. |
| open T |
getNow(valueIfAbsent: T)Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent. |
| open Int |
Returns the estimated number of CompletableFutures whose completions are awaiting completion of this CompletableFuture. |
| open CompletableFuture<U>! |
handle(fn: BiFunction<in T, Throwable!, out U>!)Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed with this stage's result and exception as arguments to the supplied function. |
| open CompletableFuture<U>! |
handleAsync(fn: BiFunction<in T, Throwable!, out U>!)Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using this stage's default asynchronous execution facility, with this stage's result and exception as arguments to the supplied function. |
| open CompletableFuture<U>! |
handleAsync(fn: BiFunction<in T, Throwable!, out U>!, executor: Executor!)Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using the supplied executor, with this stage's result and exception as arguments to the supplied function. |
| open Boolean |
Returns |
| open Boolean |
Returns |
| open Boolean |
isDone()Returns |
| open T |
join()Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally. |
| open CompletionStage<T>! |
Returns a new CompletionStage that is completed normally with the same value as this CompletableFuture when it completes normally, and cannot be independently completed or otherwise used in ways not defined by the methods of interface |
| open CompletableFuture<U>! |
Returns a new incomplete CompletableFuture of the type to be returned by a CompletionStage method. |
| open Unit |
obtrudeException(ex: Throwable!)Forcibly causes subsequent invocations of method |
| open Unit |
obtrudeValue(value: T)Forcibly sets or resets the value subsequently returned by method |
| open CompletableFuture<T>! |
Exceptionally completes this CompletableFuture with a |
| open T |
Returns the computed result, without waiting. |
| open CompletableFuture<Void!>! |
runAfterBoth(other: CompletionStage<*>!, action: Runnable!)Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action. |
| open CompletableFuture<Void!>! |
runAfterBothAsync(other: CompletionStage<*>!, action: Runnable!)Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using this stage's default asynchronous execution facility. |
| open CompletableFuture<Void!>! |
runAfterBothAsync(other: CompletionStage<*>!, action: Runnable!, executor: Executor!)Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using the supplied executor. |
| open CompletableFuture<Void!>! |
runAfterEither(other: CompletionStage<*>!, action: Runnable!)Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action. |
| open CompletableFuture<Void!>! |
runAfterEitherAsync(other: CompletionStage<*>!, action: Runnable!)Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using this stage's default asynchronous execution facility. |
| open CompletableFuture<Void!>! |
runAfterEitherAsync(other: CompletionStage<*>!, action: Runnable!, executor: Executor!)Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using the supplied executor. |
| open static CompletableFuture<Void!>! |
Returns a new CompletableFuture that is asynchronously completed by a task running in the |
| open static CompletableFuture<Void!>! |
Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor after it runs the given action. |
| open Future.State! |
state(){@return the computation state} |
| open static CompletableFuture<U>! |
supplyAsync(supplier: Supplier<U>!)Returns a new CompletableFuture that is asynchronously completed by a task running in the |
| open static CompletableFuture<U>! |
supplyAsync(supplier: Supplier<U>!, executor: Executor!)Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier. |
| open CompletableFuture<Void!>! |
thenAccept(action: Consumer<in T>!)Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action. |
| open CompletableFuture<Void!>! |
thenAcceptAsync(action: Consumer<in T>!)Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied action. |
| open CompletableFuture<Void!>! |
thenAcceptAsync(action: Consumer<in T>!, executor: Executor!)Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action. |
| open CompletableFuture<Void!>! |
thenAcceptBoth(other: CompletionStage<out U>!, action: BiConsumer<in T, in U>!)Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action. |
| open CompletableFuture<Void!>! |
thenAcceptBothAsync(other: CompletionStage<out U>!, action: BiConsumer<in T, in U>!)Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied action. |
| open CompletableFuture<Void!>! |
thenAcceptBothAsync(other: CompletionStage<out U>!, action: BiConsumer<in T, in U>!, executor: Executor!)Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action. |
| open CompletableFuture<U>! |
Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function. |
| open CompletableFuture<U>! |
thenApplyAsync(fn: Function<in T, out U>!)Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied function. |
| open CompletableFuture<U>! |
thenApplyAsync(fn: Function<in T, out U>!, executor: Executor!)Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied function. |
| open CompletableFuture<V>! |
thenCombine(other: CompletionStage<out U>!, fn: BiFunction<in T, in U, out V>!)Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function. |
| open CompletableFuture<V>! |
thenCombineAsync(other: CompletionStage<out U>!, fn: BiFunction<in T, in U, out V>!)Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied function. |
| open CompletableFuture<V>! |
thenCombineAsync(other: CompletionStage<out U>!, fn: BiFunction<in T, in U, out V>!, executor: Executor!)Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function. |
| open CompletableFuture<U>! |
thenCompose(fn: Function<in T, out CompletionStage<U>!>!)Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function. |
| open CompletableFuture<U>! |
thenComposeAsync(fn: Function<in T, out CompletionStage<U>!>!)Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using this stage's default asynchronous execution facility. |
| open CompletableFuture<U>! |
thenComposeAsync(fn: Function<in T, out CompletionStage<U>!>!, executor: Executor!)Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor. |
| open CompletableFuture<Void!>! |
Returns a new CompletionStage that, when this stage completes normally, executes the given action. |
| open CompletableFuture<Void!>! |
thenRunAsync(action: Runnable!)Returns a new CompletionStage that, when this stage completes normally, executes the given action using this stage's default asynchronous execution facility. |
| open CompletableFuture<Void!>! |
thenRunAsync(action: Runnable!, executor: Executor!)Returns a new CompletionStage that, when this stage completes normally, executes the given action using the supplied Executor. |
| open CompletableFuture<T>! |
Returns this CompletableFuture. |
| open String |
toString()Returns a string identifying this CompletableFuture, as well as its completion state. |
| open CompletableFuture<T>! |
whenComplete(action: BiConsumer<in T, in Throwable!>!)Returns a new CompletionStage with the same result or exception as this stage, that executes the given action when this stage completes. |
| open CompletableFuture<T>! |
whenCompleteAsync(action: BiConsumer<in T, in Throwable!>!)Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using this stage's default asynchronous execution facility when this stage completes. |
| open CompletableFuture<T>! |
whenCompleteAsync(action: BiConsumer<in T, in Throwable!>!, executor: Executor!)Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using the supplied Executor when this stage completes. |
Public constructors
CompletableFuture
CompletableFuture()
Creates a new incomplete CompletableFuture.
Public methods
acceptEither
open fun acceptEither(
other: CompletionStage<out T>!,
action: Consumer<in T>!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<out T>!: the other CompletionStage |
action |
Consumer<in T>!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
acceptEitherAsync
open fun acceptEitherAsync(
other: CompletionStage<out T>!,
action: Consumer<in T>!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<out T>!: the other CompletionStage |
action |
Consumer<in T>!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
acceptEitherAsync
open fun acceptEitherAsync(
other: CompletionStage<out T>!,
action: Consumer<in T>!,
executor: Executor!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<out T>!: the other CompletionStage |
action |
Consumer<in T>!: the action to perform before completing the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
allOf
open static fun allOf(vararg cfs: CompletableFuture<*>!): CompletableFuture<Void!>!
Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete. If any of the given CompletableFutures complete exceptionally, then the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. Otherwise, the results, if any, of the given CompletableFutures are not reflected in the returned CompletableFuture, but may be obtained by inspecting them individually. If no CompletableFutures are provided, returns a CompletableFuture completed with the value null.
Among the applications of this method is to await completion of a set of independent CompletableFutures before continuing a program, as in: CompletableFuture.allOf(c1, c2, c3).join();.
| Parameters | |
|---|---|
cfs |
CompletableFuture<*>!: the CompletableFutures |
| Return | |
|---|---|
CompletableFuture<Void!>! |
a new CompletableFuture that is completed when all of the given CompletableFutures complete |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
if the array or any of its elements are null |
anyOf
open static fun anyOf(vararg cfs: CompletableFuture<*>!): CompletableFuture<Any!>!
Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result. Otherwise, if it completed exceptionally, the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. If no CompletableFutures are provided, returns an incomplete CompletableFuture.
| Parameters | |
|---|---|
cfs |
CompletableFuture<*>!: the CompletableFutures |
| Return | |
|---|---|
CompletableFuture<Any!>! |
a new CompletableFuture that is completed with the result or exception of any of the given CompletableFutures when one completes |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
if the array or any of its elements are null |
applyToEither
open fun <U : Any!> applyToEither(
other: CompletionStage<out T>!,
fn: Function<in T, U>!
): CompletableFuture<U>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the function's return type |
other |
CompletionStage<out T>!: the other CompletionStage |
fn |
Function<in T, U>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
applyToEitherAsync
open fun <U : Any!> applyToEitherAsync(
other: CompletionStage<out T>!,
fn: Function<in T, U>!
): CompletableFuture<U>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the function's return type |
other |
CompletionStage<out T>!: the other CompletionStage |
fn |
Function<in T, U>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
applyToEitherAsync
open fun <U : Any!> applyToEitherAsync(
other: CompletionStage<out T>!,
fn: Function<in T, U>!,
executor: Executor!
): CompletableFuture<U>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the function's return type |
other |
CompletionStage<out T>!: the other CompletionStage |
fn |
Function<in T, U>!: the function to use to compute the value of the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
cancel
open fun cancel(mayInterruptIfRunning: Boolean): Boolean
If not already completed, completes this CompletableFuture with a CancellationException. Dependent CompletableFutures that have not already completed will also complete exceptionally, with a CompletionException caused by this CancellationException.
| Parameters | |
|---|---|
mayInterruptIfRunning |
Boolean: this value has no effect in this implementation because interrupts are not used to control processing. |
| Return | |
|---|---|
Boolean |
true if this task is now cancelled |
complete
open fun complete(value: T): Boolean
If not already completed, sets the value returned by get() and related methods to the given value.
| Parameters | |
|---|---|
value |
T: the result value |
| Return | |
|---|---|
Boolean |
true if this invocation caused this CompletableFuture to transition to a completed state, else false |
completeAsync
open fun completeAsync(supplier: Supplier<out T>!): CompletableFuture<T>!
Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the default executor.
| Parameters | |
|---|---|
supplier |
Supplier<out T>!: a function returning the value to be used to complete this CompletableFuture |
| Return | |
|---|---|
CompletableFuture<T>! |
this CompletableFuture |
completeAsync
open fun completeAsync(
supplier: Supplier<out T>!,
executor: Executor!
): CompletableFuture<T>!
Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the given executor.
| Parameters | |
|---|---|
supplier |
Supplier<out T>!: a function returning the value to be used to complete this CompletableFuture |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<T>! |
this CompletableFuture |
completeExceptionally
open fun completeExceptionally(ex: Throwable!): Boolean
If not already completed, causes invocations of get() and related methods to throw the given exception.
| Parameters | |
|---|---|
ex |
Throwable!: the exception |
| Return | |
|---|---|
Boolean |
true if this invocation caused this CompletableFuture to transition to a completed state, else false |
completeOnTimeout
open fun completeOnTimeout(
value: T,
timeout: Long,
unit: TimeUnit!
): CompletableFuture<T>!
Completes this CompletableFuture with the given value if not otherwise completed before the given timeout.
| Parameters | |
|---|---|
value |
T: the value to use upon timeout |
timeout |
Long: how long to wait before completing normally with the given value, in units of unit |
unit |
TimeUnit!: a TimeUnit determining how to interpret the timeout parameter |
| Return | |
|---|---|
CompletableFuture<T>! |
this CompletableFuture |
completedFuture
open static fun <U : Any!> completedFuture(value: U): CompletableFuture<U>!
Returns a new CompletableFuture that is already completed with the given value.
| Parameters | |
|---|---|
<U> |
the type of the value |
value |
U: the value |
| Return | |
|---|---|
CompletableFuture<U>! |
the completed CompletableFuture |
completedStage
open static fun <U : Any!> completedStage(value: U): CompletionStage<U>!
Returns a new CompletionStage that is already completed with the given value and supports only those methods in interface CompletionStage.
| Parameters | |
|---|---|
<U> |
the type of the value |
value |
U: the value |
| Return | |
|---|---|
CompletionStage<U>! |
the completed CompletionStage |
copy
open fun copy(): CompletableFuture<T>!
Returns a new CompletableFuture that is completed normally with the same value as this CompletableFuture when it completes normally. If this CompletableFuture completes exceptionally, then the returned CompletableFuture completes exceptionally with a CompletionException with this exception as cause. The behavior is equivalent to thenApply(x -> x). This method may be useful as a form of "defensive copying", to prevent clients from completing, while still being able to arrange dependent actions.
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletableFuture |
defaultExecutor
open fun defaultExecutor(): Executor!
Returns the default Executor used for async methods that do not specify an Executor. This class uses the ForkJoinPool.commonPool() if it supports more than one parallel thread, or else an Executor using one thread per async task. This method may be overridden in subclasses to return an Executor that provides at least one independent thread.
| Return | |
|---|---|
Executor! |
the executor |
delayedExecutor
open static fun delayedExecutor(
delay: Long,
unit: TimeUnit!
): Executor!
Returns a new Executor that submits a task to the default executor after the given delay (or no delay if non-positive). Each delay commences upon invocation of the returned executor's execute method.
| Parameters | |
|---|---|
delay |
Long: how long to delay, in units of unit |
unit |
TimeUnit!: a TimeUnit determining how to interpret the delay parameter |
| Return | |
|---|---|
Executor! |
the new delayed executor |
delayedExecutor
open static fun delayedExecutor(
delay: Long,
unit: TimeUnit!,
executor: Executor!
): Executor!
Returns a new Executor that submits a task to the given base executor after the given delay (or no delay if non-positive). Each delay commences upon invocation of the returned executor's execute method.
| Parameters | |
|---|---|
delay |
Long: how long to delay, in units of unit |
unit |
TimeUnit!: a TimeUnit determining how to interpret the delay parameter |
executor |
Executor!: the base executor |
| Return | |
|---|---|
Executor! |
the new delayed executor |
exceptionNow
open fun exceptionNow(): Throwable!
Returns the exception thrown by the task, without waiting.
This method is for cases where the caller knows that the task has already completed with an exception.
| Return | |
|---|---|
Throwable! |
the exception thrown by the task |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
if the task has not completed, the task completed normally, or the task was cancelled |
exceptionally
open fun exceptionally(fn: Function<Throwable!, out T>!): CompletableFuture<T>!
Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function. Otherwise, if this stage completes normally, then the returned stage also completes normally with the same value.
| Parameters | |
|---|---|
fn |
Function<Throwable!, out T>!: the function to use to compute the value of the returned CompletionStage if this CompletionStage completed exceptionally |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
exceptionallyAsync
open fun exceptionallyAsync(fn: Function<Throwable!, out T>!): CompletableFuture<T>!
Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, using this stage's default asynchronous execution facility. Otherwise, if this stage completes normally, then the returned stage also completes normally with the same value.
| Parameters | |
|---|---|
fn |
Function<Throwable!, out T>!: the function to use to compute the value of the returned CompletionStage if this CompletionStage completed exceptionally |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
exceptionallyAsync
open fun exceptionallyAsync(
fn: Function<Throwable!, out T>!,
executor: Executor!
): CompletableFuture<T>!
Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function, using the supplied Executor. Otherwise, if this stage completes normally, then the returned stage also completes normally with the same value.
| Parameters | |
|---|---|
fn |
Function<Throwable!, out T>!: the function to use to compute the value of the returned CompletionStage if this CompletionStage completed exceptionally |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
exceptionallyCompose
open fun exceptionallyCompose(fn: Function<Throwable!, out CompletionStage<T>!>!): CompletableFuture<T>!
Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception.
| Parameters | |
|---|---|
fn |
Function<Throwable!, out CompletionStage<T>!>!: the function to use to compute the returned CompletionStage if this CompletionStage completed exceptionally |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
exceptionallyComposeAsync
open fun exceptionallyComposeAsync(fn: Function<Throwable!, out CompletionStage<T>!>!): CompletableFuture<T>!
Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, using this stage's default asynchronous execution facility.
| Parameters | |
|---|---|
fn |
Function<Throwable!, out CompletionStage<T>!>!: the function to use to compute the returned CompletionStage if this CompletionStage completed exceptionally |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
exceptionallyComposeAsync
open fun exceptionallyComposeAsync(
fn: Function<Throwable!, out CompletionStage<T>!>!,
executor: Executor!
): CompletableFuture<T>!
Returns a new CompletionStage that, when this stage completes exceptionally, is composed using the results of the supplied function applied to this stage's exception, using the supplied Executor.
| Parameters | |
|---|---|
fn |
Function<Throwable!, out CompletionStage<T>!>!: the function to use to compute the returned CompletionStage if this CompletionStage completed exceptionally |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
failedFuture
open static fun <U : Any!> failedFuture(ex: Throwable!): CompletableFuture<U>!
Returns a new CompletableFuture that is already completed exceptionally with the given exception.
| Parameters | |
|---|---|
<U> |
the type of the value |
ex |
Throwable!: the exception |
| Return | |
|---|---|
CompletableFuture<U>! |
the exceptionally completed CompletableFuture |
failedStage
open static fun <U : Any!> failedStage(ex: Throwable!): CompletionStage<U>!
Returns a new CompletionStage that is already completed exceptionally with the given exception and supports only those methods in interface CompletionStage.
| Parameters | |
|---|---|
<U> |
the type of the value |
ex |
Throwable!: the exception |
| Return | |
|---|---|
CompletionStage<U>! |
the exceptionally completed CompletionStage |
get
open fun get(): T
Waits if necessary for this future to complete, and then returns its result.
| Return | |
|---|---|
T |
the result value |
| Exceptions | |
|---|---|
java.lang.InterruptedException |
if the current thread was interrupted while waiting |
java.util.concurrent.CancellationException |
if this future was cancelled |
java.util.concurrent.ExecutionException |
if this future completed exceptionally |
get
open fun get(
timeout: Long,
unit: TimeUnit!
): T
Waits if necessary for at most the given time for this future to complete, and then returns its result, if available.
| Parameters | |
|---|---|
timeout |
Long: the maximum time to wait |
unit |
TimeUnit!: the time unit of the timeout argument |
| Return | |
|---|---|
T |
the result value |
| Exceptions | |
|---|---|
java.lang.InterruptedException |
if the current thread was interrupted while waiting |
java.util.concurrent.CancellationException |
if this future was cancelled |
java.util.concurrent.ExecutionException |
if this future completed exceptionally |
java.util.concurrent.TimeoutException |
if the wait timed out |
getNow
open fun getNow(valueIfAbsent: T): T
Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.
| Parameters | |
|---|---|
valueIfAbsent |
T: the value to return if not completed |
| Return | |
|---|---|
T |
the result value, if completed, else the given valueIfAbsent |
| Exceptions | |
|---|---|
java.util.concurrent.CancellationException |
if the computation was cancelled |
java.util.concurrent.CompletionException |
if this future completed exceptionally or a completion computation threw an exception |
getNumberOfDependents
open fun getNumberOfDependents(): Int
Returns the estimated number of CompletableFutures whose completions are awaiting completion of this CompletableFuture. This method is designed for use in monitoring system state, not for synchronization control.
| Return | |
|---|---|
Int |
the number of dependent CompletableFutures |
handle
open fun <U : Any!> handle(fn: BiFunction<in T, Throwable!, out U>!): CompletableFuture<U>!
Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed with this stage's result and exception as arguments to the supplied function.
When this stage is complete, the given function is invoked with the result (or null if none) and the exception (or null if none) of this stage as arguments, and the function's result is used to complete the returned stage.
| Parameters | |
|---|---|
<U> |
the function's return type |
fn |
BiFunction<in T, Throwable!, out U>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
handleAsync
open fun <U : Any!> handleAsync(fn: BiFunction<in T, Throwable!, out U>!): CompletableFuture<U>!
Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using this stage's default asynchronous execution facility, with this stage's result and exception as arguments to the supplied function.
When this stage is complete, the given function is invoked with the result (or null if none) and the exception (or null if none) of this stage as arguments, and the function's result is used to complete the returned stage.
| Parameters | |
|---|---|
<U> |
the function's return type |
fn |
BiFunction<in T, Throwable!, out U>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
handleAsync
open fun <U : Any!> handleAsync(
fn: BiFunction<in T, Throwable!, out U>!,
executor: Executor!
): CompletableFuture<U>!
Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using the supplied executor, with this stage's result and exception as arguments to the supplied function.
When this stage is complete, the given function is invoked with the result (or null if none) and the exception (or null if none) of this stage as arguments, and the function's result is used to complete the returned stage.
| Parameters | |
|---|---|
<U> |
the function's return type |
fn |
BiFunction<in T, Throwable!, out U>!: the function to use to compute the value of the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
isCancelled
open fun isCancelled(): Boolean
Returns true if this CompletableFuture was cancelled before it completed normally.
| Return | |
|---|---|
Boolean |
true if this CompletableFuture was cancelled before it completed normally |
isCompletedExceptionally
open fun isCompletedExceptionally(): Boolean
Returns true if this CompletableFuture completed exceptionally, in any way. Possible causes include cancellation, explicit invocation of completeExceptionally, and abrupt termination of a CompletionStage action.
| Return | |
|---|---|
Boolean |
true if this CompletableFuture completed exceptionally |
isDone
open fun isDone(): Boolean
Returns true if completed in any fashion: normally, exceptionally, or via cancellation.
| Return | |
|---|---|
Boolean |
true if completed |
join
open fun join(): T
Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally. To better conform with the use of common functional forms, if a computation involved in the completion of this CompletableFuture threw an exception, this method throws an (unchecked) CompletionException with the underlying exception as its cause.
| Return | |
|---|---|
T |
the result value |
| Exceptions | |
|---|---|
java.util.concurrent.CancellationException |
if the computation was cancelled |
java.util.concurrent.CompletionException |
if this future completed exceptionally or a completion computation threw an exception |
minimalCompletionStage
open fun minimalCompletionStage(): CompletionStage<T>!
Returns a new CompletionStage that is completed normally with the same value as this CompletableFuture when it completes normally, and cannot be independently completed or otherwise used in ways not defined by the methods of interface CompletionStage. If this CompletableFuture completes exceptionally, then the returned CompletionStage completes exceptionally with a CompletionException with this exception as cause.
Unless overridden by a subclass, a new non-minimal CompletableFuture with all methods available can be obtained from a minimal CompletionStage via toCompletableFuture(). For example, completion of a minimal stage can be awaited by
<code>minimalStage.toCompletableFuture().join(); </code>
| Return | |
|---|---|
CompletionStage<T>! |
the new CompletionStage |
newIncompleteFuture
open fun <U : Any!> newIncompleteFuture(): CompletableFuture<U>!
Returns a new incomplete CompletableFuture of the type to be returned by a CompletionStage method. Subclasses should normally override this method to return an instance of the same class as this CompletableFuture. The default implementation returns an instance of class CompletableFuture.
| Parameters | |
|---|---|
<U> |
the type of the value |
| Return | |
|---|---|
CompletableFuture<U>! |
a new CompletableFuture |
obtrudeException
open fun obtrudeException(ex: Throwable!): Unit
Forcibly causes subsequent invocations of method get() and related methods to throw the given exception, whether or not already completed. This method is designed for use only in error recovery actions, and even in such situations may result in ongoing dependent completions using established versus overwritten outcomes.
| Parameters | |
|---|---|
ex |
Throwable!: the exception |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
if the exception is null |
obtrudeValue
open fun obtrudeValue(value: T): Unit
Forcibly sets or resets the value subsequently returned by method get() and related methods, whether or not already completed. This method is designed for use only in error recovery actions, and even in such situations may result in ongoing dependent completions using established versus overwritten outcomes.
| Parameters | |
|---|---|
value |
T: the completion value |
orTimeout
open fun orTimeout(
timeout: Long,
unit: TimeUnit!
): CompletableFuture<T>!
Exceptionally completes this CompletableFuture with a TimeoutException if not otherwise completed before the given timeout.
| Parameters | |
|---|---|
timeout |
Long: how long to wait before completing exceptionally with a TimeoutException, in units of unit |
unit |
TimeUnit!: a TimeUnit determining how to interpret the timeout parameter |
| Return | |
|---|---|
CompletableFuture<T>! |
this CompletableFuture |
resultNow
open fun resultNow(): T
Returns the computed result, without waiting.
This method is for cases where the caller knows that the task has already completed successfully, for example when filtering a stream of Future objects for the successful tasks and using a mapping operation to obtain a stream of results. {@snippet lang=java : * results = futures.stream() * .filter(f -> f.state() == Future.State.SUCCESS) * .map(Future::resultNow) * .toList(); * }
| Return | |
|---|---|
T |
the computed result |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
if the task has not completed or the task did not complete with a result |
runAfterBoth
open fun runAfterBoth(
other: CompletionStage<*>!,
action: Runnable!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<*>!: the other CompletionStage |
action |
Runnable!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
runAfterBothAsync
open fun runAfterBothAsync(
other: CompletionStage<*>!,
action: Runnable!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using this stage's default asynchronous execution facility. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<*>!: the other CompletionStage |
action |
Runnable!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
runAfterBothAsync
open fun runAfterBothAsync(
other: CompletionStage<*>!,
action: Runnable!,
executor: Executor!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using the supplied executor. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<*>!: the other CompletionStage |
action |
Runnable!: the action to perform before completing the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
runAfterEither
open fun runAfterEither(
other: CompletionStage<*>!,
action: Runnable!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<*>!: the other CompletionStage |
action |
Runnable!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
runAfterEitherAsync
open fun runAfterEitherAsync(
other: CompletionStage<*>!,
action: Runnable!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using this stage's default asynchronous execution facility. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<*>!: the other CompletionStage |
action |
Runnable!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
runAfterEitherAsync
open fun runAfterEitherAsync(
other: CompletionStage<*>!,
action: Runnable!,
executor: Executor!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using the supplied executor. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
other |
CompletionStage<*>!: the other CompletionStage |
action |
Runnable!: the action to perform before completing the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
runAsync
open static fun runAsync(runnable: Runnable!): CompletableFuture<Void!>!
Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool.commonPool() after it runs the given action.
| Parameters | |
|---|---|
runnable |
Runnable!: the action to run before completing the returned CompletableFuture |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletableFuture |
runAsync
open static fun runAsync(
runnable: Runnable!,
executor: Executor!
): CompletableFuture<Void!>!
Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor after it runs the given action.
| Parameters | |
|---|---|
runnable |
Runnable!: the action to run before completing the returned CompletableFuture |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletableFuture |
supplyAsync
open static fun <U : Any!> supplyAsync(supplier: Supplier<U>!): CompletableFuture<U>!
Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool.commonPool() with the value obtained by calling the given Supplier.
| Parameters | |
|---|---|
<U> |
the function's return type |
supplier |
Supplier<U>!: a function returning the value to be used to complete the returned CompletableFuture |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletableFuture |
supplyAsync
open static fun <U : Any!> supplyAsync(
supplier: Supplier<U>!,
executor: Executor!
): CompletableFuture<U>!
Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier.
| Parameters | |
|---|---|
<U> |
the function's return type |
supplier |
Supplier<U>!: a function returning the value to be used to complete the returned CompletableFuture |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletableFuture |
thenAccept
open fun thenAccept(action: Consumer<in T>!): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
action |
Consumer<in T>!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenAcceptAsync
open fun thenAcceptAsync(action: Consumer<in T>!): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
action |
Consumer<in T>!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenAcceptAsync
open fun thenAcceptAsync(
action: Consumer<in T>!,
executor: Executor!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
action |
Consumer<in T>!: the action to perform before completing the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenAcceptBoth
open fun <U : Any!> thenAcceptBoth(
other: CompletionStage<out U>!,
action: BiConsumer<in T, in U>!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the other CompletionStage's result |
other |
CompletionStage<out U>!: the other CompletionStage |
action |
BiConsumer<in T, in U>!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenAcceptBothAsync
open fun <U : Any!> thenAcceptBothAsync(
other: CompletionStage<out U>!,
action: BiConsumer<in T, in U>!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the other CompletionStage's result |
other |
CompletionStage<out U>!: the other CompletionStage |
action |
BiConsumer<in T, in U>!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenAcceptBothAsync
open fun <U : Any!> thenAcceptBothAsync(
other: CompletionStage<out U>!,
action: BiConsumer<in T, in U>!,
executor: Executor!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the other CompletionStage's result |
other |
CompletionStage<out U>!: the other CompletionStage |
action |
BiConsumer<in T, in U>!: the action to perform before completing the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenApply
open fun <U : Any!> thenApply(fn: Function<in T, out U>!): CompletableFuture<U>!
Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function.
This method is analogous to Optional.map and Stream.map.
See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the function's return type |
fn |
Function<in T, out U>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
thenApplyAsync
open fun <U : Any!> thenApplyAsync(fn: Function<in T, out U>!): CompletableFuture<U>!
Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the function's return type |
fn |
Function<in T, out U>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
thenApplyAsync
open fun <U : Any!> thenApplyAsync(
fn: Function<in T, out U>!,
executor: Executor!
): CompletableFuture<U>!
Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the function's return type |
fn |
Function<in T, out U>!: the function to use to compute the value of the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
thenCombine
open fun <U : Any!, V : Any!> thenCombine(
other: CompletionStage<out U>!,
fn: BiFunction<in T, in U, out V>!
): CompletableFuture<V>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the other CompletionStage's result |
<V> |
the function's return type |
other |
CompletionStage<out U>!: the other CompletionStage |
fn |
BiFunction<in T, in U, out V>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<V>! |
the new CompletionStage |
thenCombineAsync
open fun <U : Any!, V : Any!> thenCombineAsync(
other: CompletionStage<out U>!,
fn: BiFunction<in T, in U, out V>!
): CompletableFuture<V>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the other CompletionStage's result |
<V> |
the function's return type |
other |
CompletionStage<out U>!: the other CompletionStage |
fn |
BiFunction<in T, in U, out V>!: the function to use to compute the value of the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<V>! |
the new CompletionStage |
thenCombineAsync
open fun <U : Any!, V : Any!> thenCombineAsync(
other: CompletionStage<out U>!,
fn: BiFunction<in T, in U, out V>!,
executor: Executor!
): CompletableFuture<V>!
Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the other CompletionStage's result |
<V> |
the function's return type |
other |
CompletionStage<out U>!: the other CompletionStage |
fn |
BiFunction<in T, in U, out V>!: the function to use to compute the value of the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<V>! |
the new CompletionStage |
thenCompose
open fun <U : Any!> thenCompose(fn: Function<in T, out CompletionStage<U>!>!): CompletableFuture<U>!
Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function.
When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the CompletionStage returned by this method is completed with the same value.
To ensure progress, the supplied function must arrange eventual completion of its result.
This method is analogous to Optional.flatMap and Stream.flatMap.
See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the returned CompletionStage's result |
fn |
Function<in T, out CompletionStage<U>!>!: the function to use to compute another CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
thenComposeAsync
open fun <U : Any!> thenComposeAsync(fn: Function<in T, out CompletionStage<U>!>!): CompletableFuture<U>!
Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using this stage's default asynchronous execution facility.
When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the CompletionStage returned by this method is completed with the same value.
To ensure progress, the supplied function must arrange eventual completion of its result.
See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the returned CompletionStage's result |
fn |
Function<in T, out CompletionStage<U>!>!: the function to use to compute another CompletionStage |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
thenComposeAsync
open fun <U : Any!> thenComposeAsync(
fn: Function<in T, out CompletionStage<U>!>!,
executor: Executor!
): CompletableFuture<U>!
Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor.
When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the CompletionStage returned by this method is completed with the same value.
To ensure progress, the supplied function must arrange eventual completion of its result.
See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
<U> |
the type of the returned CompletionStage's result |
fn |
Function<in T, out CompletionStage<U>!>!: the function to use to compute another CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<U>! |
the new CompletionStage |
thenRun
open fun thenRun(action: Runnable!): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this stage completes normally, executes the given action. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
action |
Runnable!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenRunAsync
open fun thenRunAsync(action: Runnable!): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this stage completes normally, executes the given action using this stage's default asynchronous execution facility. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
action |
Runnable!: the action to perform before completing the returned CompletionStage |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
thenRunAsync
open fun thenRunAsync(
action: Runnable!,
executor: Executor!
): CompletableFuture<Void!>!
Returns a new CompletionStage that, when this stage completes normally, executes the given action using the supplied Executor. See the CompletionStage documentation for rules covering exceptional completion.
| Parameters | |
|---|---|
action |
Runnable!: the action to perform before completing the returned CompletionStage |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<Void!>! |
the new CompletionStage |
toCompletableFuture
open fun toCompletableFuture(): CompletableFuture<T>!
Returns this CompletableFuture.
| Return | |
|---|---|
CompletableFuture<T>! |
this CompletableFuture |
toString
open fun toString(): String
Returns a string identifying this CompletableFuture, as well as its completion state. The state, in brackets, contains the String "Completed Normally" or the String "Completed Exceptionally", or the String "Not completed" followed by the number of CompletableFutures dependent upon its completion, if any.
| Return | |
|---|---|
String |
a string identifying this CompletableFuture, as well as its state |
whenComplete
open fun whenComplete(action: BiConsumer<in T, in Throwable!>!): CompletableFuture<T>!
Returns a new CompletionStage with the same result or exception as this stage, that executes the given action when this stage completes.
When this stage is complete, the given action is invoked with the result (or null if none) and the exception (or null if none) of this stage as arguments. The returned stage is completed when the action returns.
Unlike method handle, this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: if this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception.
| Parameters | |
|---|---|
action |
BiConsumer<in T, in Throwable!>!: the action to perform |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
whenCompleteAsync
open fun whenCompleteAsync(action: BiConsumer<in T, in Throwable!>!): CompletableFuture<T>!
Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using this stage's default asynchronous execution facility when this stage completes.
When this stage is complete, the given action is invoked with the result (or null if none) and the exception (or null if none) of this stage as arguments. The returned stage is completed when the action returns.
Unlike method handleAsync, this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: If this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception.
| Parameters | |
|---|---|
action |
BiConsumer<in T, in Throwable!>!: the action to perform |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |
whenCompleteAsync
open fun whenCompleteAsync(
action: BiConsumer<in T, in Throwable!>!,
executor: Executor!
): CompletableFuture<T>!
Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using the supplied Executor when this stage completes.
When this stage is complete, the given action is invoked with the result (or null if none) and the exception (or null if none) of this stage as arguments. The returned stage is completed when the action returns.
Unlike method handleAsync, this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: If this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception.
| Parameters | |
|---|---|
action |
BiConsumer<in T, in Throwable!>!: the action to perform |
executor |
Executor!: the executor to use for asynchronous execution |
| Return | |
|---|---|
CompletableFuture<T>! |
the new CompletionStage |