Top Description Inners Fields Constructors Methods
java.util.concurrent

public Class CompletableFuture<T>

extends Object
implements Future<T>, CompletionStage<T>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.CompletionStage, java.util.concurrent.Future
Known Direct Subclasses
java.util.concurrent.CompletableFuture.MinimalStage, java.lang.ProcessHandleImpl.ExitCompletion
Type Parameters
<T>
The result type returned by this future's join and get methods
Imports
java.lang.invoke.MethodHandles, .VarHandle, java.util.concurrent.locks.LockSupport, java.util.function.BiConsumer, .BiFunction, .Consumer, .Function, .Supplier, java.util.Objects

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:

CompletableFuture also implements Future with the following policies:

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.

Subclasses of this class should normally override the "virtual constructor" method newIncompleteFuture, which establishes the concrete type returned by CompletionStage methods. For example, here is a class that substitutes a different default Executor and disables the obtrude methods:

 class MyCompletableFuture<T> extends CompletableFuture<T> {
  static final Executor myExecutor = ...;
  public MyCompletableFuture() { }
  public <U> CompletableFuture<U> newIncompleteFuture() {
    return new MyCompletableFuture<U>(); }
  public Executor defaultExecutor() {
    return myExecutor; }
  public void obtrudeValue(T value) {
    throw new UnsupportedOperationException(); }
  public void obtrudeException(Throwable ex) {
    throw new UnsupportedOperationException(); }
}
Author
Doug Lea
Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
CompletableFuture.AnyOf

Completion for an anyOf input future.

public static interface
CompletableFuture.AsynchronousCompletionTask

A marker interface identifying asynchronous tasks produced by async methods.

pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv abstract static class
CompletableFuture.BiCompletion<T, U, V>

A Completion for an action with two sources

pack-priv static class
pack-priv static class
pack-priv static class
CompletableFuture.Canceller

Action to cancel unneeded timeouts

pack-priv static class
CompletableFuture.CoCompletion

A Completion delegating to a BiCompletion

pack-priv abstract static class
pack-priv static class
CompletableFuture.DelayedCompleter<U>

Action to complete on timeout

pack-priv static class
pack-priv static class
CompletableFuture.Delayer

Singleton delay scheduler, used only for starting and cancelling tasks.

pack-priv static class
CompletableFuture.MinimalStage<T>

A subclass that just throws UOE for most non-CompletionStage methods.

pack-priv static class
pack-priv static class
CompletableFuture.OrApply<T, U extends T, V>

pack-priv static class
pack-priv static class
CompletableFuture.Signaller

Completion for recording and releasing a waiting thread.

pack-priv static class
CompletableFuture.TaskSubmitter

Action to submit user task

private static class
CompletableFuture.ThreadPerTaskExecutor

Fallback if ForkJoinPool.commonPool() cannot support parallelism

pack-priv static class
CompletableFuture.Timeout

Action to completeExceptionally on timeout

pack-priv static class
pack-priv static class
pack-priv abstract static class
CompletableFuture.UniCompletion<T, V>

A Completion with a source, dependent, and executor.

pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final int
private static final Executor
ASYNC_POOL

Default executor -- ForkJoinPool.commonPool() unless it cannot support parallelism.

pack-priv static final int
private static final VarHandle
pack-priv static final CompletableFuture.AltResult
NIL

The encoding of the null value.

pack-priv volatile Object
private static final VarHandle
pack-priv volatile CompletableFuture.Completion
private static final VarHandle
pack-priv static final int
private static final boolean

Constructor Summary

AccessConstructor and Description
public
CompletableFuture()

Creates a new incomplete CompletableFuture.

pack-priv
CompletableFuture(Object r)

Creates a new complete CompletableFuture with given encoded result.

Method Summary

Modifier and TypeMethod and Description
public CompletableFuture<Void>
acceptEither(CompletionStage<? extends T>
the other CompletionStage
other
,
Consumer<? super T>
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.acceptEither.

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.

public CompletableFuture<Void>
acceptEitherAsync(CompletionStage<? extends T>
the other CompletionStage
other
,
Consumer<? super T>
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.acceptEitherAsync.

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.

public CompletableFuture<Void>
acceptEitherAsync(CompletionStage<? extends T>
the other CompletionStage
other
,
Consumer<? super T>
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.acceptEitherAsync.

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.

public static CompletableFuture<Void>

Returns:

a new CompletableFuture that is completed when all of the given CompletableFutures complete
allOf
(CompletableFuture<?>...
the CompletableFutures
cfs
)

Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete.

pack-priv static CompletableFuture<Void>
andTree(CompletableFuture<?>[] cfs, int lo, int hi)

Recursively constructs a tree of completions.

public static CompletableFuture<Object>

Returns:

a new CompletableFuture that is completed with the result or exception of any of the given CompletableFutures when one completes
anyOf
(CompletableFuture<?>...
the CompletableFutures
cfs
)

Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result.

public <U> CompletableFuture<U>
applyToEither(CompletionStage<? extends T>
the other CompletionStage
other
,
Function<? super T, U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.applyToEither.

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.

public <U> CompletableFuture<U>
applyToEitherAsync(CompletionStage<? extends T>
the other CompletionStage
other
,
Function<? super T, U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.applyToEitherAsync.

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.

public <U> CompletableFuture<U>
applyToEitherAsync(CompletionStage<? extends T>
the other CompletionStage
other
,
Function<? super T, U>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.applyToEitherAsync.

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.

pack-priv static CompletableFuture<Void>
pack-priv static <U> CompletableFuture<U>
pack-priv final <R, S> boolean
biAccept(Object r, Object s, BiConsumer<? super R, ? super S> f, CompletableFuture.BiAccept<R, S> c)

private <U> CompletableFuture<Void>
biAcceptStage(Executor e, CompletionStage<U> o, BiConsumer<? super T, ? super U> f)

pack-priv final <R, S> boolean
biApply(Object r, Object s, BiFunction<? super R, ? super S, ? extends T> f, CompletableFuture.BiApply<R, S, T> c)

private <U, V> CompletableFuture<V>
biApplyStage(Executor e, CompletionStage<U> o, BiFunction<? super T, ? super U, ? extends V> f)

pack-priv final void
bipush(CompletableFuture<?> b, CompletableFuture.BiCompletion<?, ?, ?> c)

Pushes completion to this and b unless both done.

pack-priv final boolean
private CompletableFuture<Void>
public boolean

Returns:

true if this task is now cancelled
cancel
(boolean
this value has no effect in this implementation because interrupts are not used to control processing.
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

If not already completed, completes this CompletableFuture with a CancellationException.

pack-priv final void
cleanStack()

Traverses stack and unlinks one or more dead Completions, if found.

public boolean

Returns:

true if this invocation caused this CompletableFuture to transition to a completed state, else false
complete
(T
the result value
value
)

If not already completed, sets the value returned by get() and related methods to the given value.

public CompletableFuture<T>

Returns:

this CompletableFuture
completeAsync
(Supplier<? extends T>
a function returning the value to be used to complete this CompletableFuture
supplier
,
Executor
the executor to use for asynchronous execution
executor
)

Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the given executor.

public CompletableFuture<T>

Returns:

this CompletableFuture
completeAsync
(Supplier<? extends T>
a function returning the value to be used to complete this CompletableFuture
supplier
)

Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the default executor.

public static <
the type of the value
U
>
CompletableFuture<U>

Returns:

the completed CompletableFuture
completedFuture
(U
the value
value
)

Returns a new CompletableFuture that is already completed with the given value.

public static <
the type of the value
U
>
CompletionStage<U>

Returns:

the completed CompletionStage
completedStage
(U
the value
value
)

Returns a new CompletionStage that is already completed with the given value and supports only those methods in interface CompletionStage.

public boolean

Returns:

true if this invocation caused this CompletableFuture to transition to a completed state, else false
completeExceptionally
(Throwable
the exception
ex
)

If not already completed, causes invocations of get() and related methods to throw the given exception.

pack-priv final boolean
completeNull()

Completes with the null value, unless already completed.

public CompletableFuture<T>

Returns:

this CompletableFuture
completeOnTimeout
(T
the value to use upon timeout
value
,
long
how long to wait before completing normally with the given value, in units of unit
timeout
,
TimeUnit
a TimeUnit determining how to interpret the timeout parameter
unit
)

Completes this CompletableFuture with the given value if not otherwise completed before the given timeout.

pack-priv final boolean
completeRelay(Object r)

Completes with r or a copy of r, unless already completed.

pack-priv final boolean
completeThrowable(Throwable x)

Completes with an exceptional result, unless already completed.

pack-priv final boolean
completeThrowable(Throwable x, Object r)

Completes with the given (non-null) exceptional result as a wrapped CompletionException unless it is one already, unless already completed.

pack-priv final boolean
completeValue(T t)

Completes with a non-exceptional result, unless already completed.

public CompletableFuture<T>

Returns:

the new CompletableFuture
copy
()

Returns a new CompletableFuture that is completed normally with the same value as this CompletableFuture when it completes normally.

public Executor

Returns:

the executor
defaultExecutor
()

Returns the default Executor used for async methods that do not specify an Executor.

public static Executor

Returns:

the new delayed executor
delayedExecutor
(long
how long to delay, in units of unit
delay
,
TimeUnit
a TimeUnit determining how to interpret the delay parameter
unit
,
Executor
the base 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).

public static Executor

Returns:

the new delayed executor
delayedExecutor
(long
how long to delay, in units of unit
delay
,
TimeUnit
a TimeUnit determining how to interpret the delay parameter
unit
)

Returns a new Executor that submits a task to the default executor after the given delay (or no delay if non-positive).

pack-priv Object
encodeOutcome(T t, Throwable x)

Returns the encoding of the given arguments: if the exception is non-null, encodes as AltResult.

pack-priv static Object
encodeRelay(Object r)

Returns the encoding of a copied outcome; if exceptional, rewraps as a CompletionException, else returns argument.

pack-priv static CompletableFuture.AltResult
encodeThrowable(Throwable x)

Returns the encoding of the given (non-null) exception as a wrapped CompletionException unless it is one already.

pack-priv static Object
encodeThrowable(Throwable x, Object r)

Returns the encoding of the given (non-null) exception as a wrapped CompletionException unless it is one already.

pack-priv final Object
encodeValue(T t)

Returns the encoding of the given non-exceptional value.

public CompletableFuture<T>
exceptionally(Function<Throwable, ? extends T>
the function to use to compute the value of the returned CompletionStage if this CompletionStage completed exceptionally
fn
)

Implements java.util.concurrent.CompletionStage.exceptionally.

Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function.

public CompletableFuture<T>
exceptionallyAsync(Function<Throwable, ? extends T>
the function to use to compute the value of the returned CompletionStage if this CompletionStage completed exceptionally
fn
)

Overrides default java.util.concurrent.CompletionStage.exceptionallyAsync.

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.

public CompletableFuture<T>
exceptionallyAsync(Function<Throwable, ? extends T>
the function to use to compute the value of the returned CompletionStage if this CompletionStage completed exceptionally
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Overrides default java.util.concurrent.CompletionStage.exceptionallyAsync.

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.

public CompletableFuture<T>
exceptionallyCompose(Function<Throwable, ? extends CompletionStage<T>>
the function to use to compute the returned CompletionStage if this CompletionStage completed exceptionally
fn
)

Overrides default java.util.concurrent.CompletionStage.exceptionallyCompose.

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.

public CompletableFuture<T>
exceptionallyComposeAsync(Function<Throwable, ? extends CompletionStage<T>>
the function to use to compute the returned CompletionStage if this CompletionStage completed exceptionally
fn
)

Overrides default java.util.concurrent.CompletionStage.exceptionallyComposeAsync.

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.

public CompletableFuture<T>
exceptionallyComposeAsync(Function<Throwable, ? extends CompletionStage<T>>
the function to use to compute the returned CompletionStage if this CompletionStage completed exceptionally
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Overrides default java.util.concurrent.CompletionStage.exceptionallyComposeAsync.

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.

public Throwable
exceptionNow()

Overrides default java.util.concurrent.Future.exceptionNow.

Returns the exception thrown by the task, without waiting.

public static <
the type of the value
U
>
CompletableFuture<U>

Returns:

the exceptionally completed CompletableFuture
failedFuture
(Throwable
the exception
ex
)

Returns a new CompletableFuture that is already completed exceptionally with the given exception.

public static <
the type of the value
U
>
CompletionStage<U>

Returns:

the exceptionally completed CompletionStage
failedStage
(Throwable
the exception
ex
)

Returns a new CompletionStage that is already completed exceptionally with the given exception and supports only those methods in interface CompletionStage.

public T

Returns:

the result value
get
()

Implements java.util.concurrent.Future.get.

Waits if necessary for this future to complete, and then returns its result.

public T

Returns:

the result value
get
(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for this future to complete, and then returns its result, if available.

public T

Returns:

the result value, if completed, else the given valueIfAbsent
getNow
(T
the value to return if not completed
valueIfAbsent
)

Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.

public int

Returns:

the number of dependent CompletableFutures
getNumberOfDependents
()

Returns the estimated number of CompletableFutures whose completions are awaiting completion of this CompletableFuture.

public <U> CompletableFuture<U>
handle(BiFunction<? super T, Throwable, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.handle.

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.

public <U> CompletableFuture<U>
handleAsync(BiFunction<? super T, Throwable, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.handleAsync.

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.

public <U> CompletableFuture<U>
handleAsync(BiFunction<? super T, Throwable, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.handleAsync.

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.

pack-priv final boolean
public boolean

Returns:

true if this CompletableFuture was cancelled before it completed normally
isCancelled
()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this CompletableFuture was cancelled before it completed normally.

public boolean

Returns:

true if this CompletableFuture completed exceptionally
isCompletedExceptionally
()

Returns true if this CompletableFuture completed exceptionally, in any way.

public boolean

Returns:

true if completed
isDone
()

Implements java.util.concurrent.Future.isDone.

Returns true if completed in any fashion: normally, exceptionally, or via cancellation.

public T

Returns:

the result value
join
()

Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally.

public CompletionStage<T>

Returns:

the new CompletionStage
minimalCompletionStage
()

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.

public <
the type of the value
U
>
CompletableFuture<U>

Returns:

a new CompletableFuture
newIncompleteFuture
()

Returns a new incomplete CompletableFuture of the type to be returned by a CompletionStage method.

public void
obtrudeException(Throwable
the exception
ex
)

Forcibly causes subsequent invocations of method get() and related methods to throw the given exception, whether or not already completed.

public void
obtrudeValue(T
the completion value
value
)

Forcibly sets or resets the value subsequently returned by method get() and related methods, whether or not already completed.

private <U extends T> CompletableFuture<Void>
private <U extends T, V> CompletableFuture<V>
orApplyStage(Executor e, CompletionStage<U> o, Function<? super T, ? extends V> f)

pack-priv final void
orpush(CompletableFuture<?> b, CompletableFuture.BiCompletion<?, ?, ?> c)

Pushes completion to this and b unless either done.

private CompletableFuture<Void>
public CompletableFuture<T>

Returns:

this CompletableFuture
orTimeout
(long
how long to wait before completing exceptionally with a TimeoutException, in units of unit
timeout
,
TimeUnit
a TimeUnit determining how to interpret the timeout parameter
unit
)

Exceptionally completes this CompletableFuture with a TimeoutException if not otherwise completed before the given timeout.

pack-priv final void
postComplete()

Pops and tries to trigger all reachable dependents.

pack-priv final CompletableFuture<T>
postFire(CompletableFuture<?> a, int mode)

Post-processing by dependent after successful UniCompletion tryFire.

pack-priv final CompletableFuture<T>
postFire(CompletableFuture<?> a, CompletableFuture<?> b, int mode)

Post-processing after successful BiCompletion tryFire.

pack-priv final void
pushStack(CompletableFuture.Completion c)

Unconditionally pushes c onto stack, retrying if necessary.

private static Object
reportGet(Object r, String details)

Reports result using Future.get conventions.

private static Object
reportJoin(Object r, String details)

Decodes outcome to return result or throw unchecked exception.

public T
resultNow()

Overrides default java.util.concurrent.Future.resultNow.

Returns the computed result, without waiting.

public CompletableFuture<Void>
runAfterBoth(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.runAfterBoth.

Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action.

public CompletableFuture<Void>
runAfterBothAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.runAfterBothAsync.

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.

public CompletableFuture<Void>
runAfterBothAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.runAfterBothAsync.

Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using the supplied executor.

public CompletableFuture<Void>
runAfterEither(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.runAfterEither.

Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action.

public CompletableFuture<Void>
runAfterEitherAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.runAfterEitherAsync.

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.

public CompletableFuture<Void>
runAfterEitherAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.runAfterEitherAsync.

Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using the supplied executor.

public static CompletableFuture<Void>

Returns:

the new CompletableFuture
runAsync
(Runnable
the action to run before completing the returned CompletableFuture
runnable
)

Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool#commonPool() after it runs the given action.

public static CompletableFuture<Void>

Returns:

the new CompletableFuture
runAsync
(Runnable
the action to run before completing the returned CompletableFuture
runnable
,
Executor
the executor to use for asynchronous execution
executor
)

Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor after it runs the given action.

pack-priv static Executor
screenExecutor(Executor e)

Null-checks user executor argument, and translates uses of commonPool to ASYNC_POOL in case parallelism disabled.

public Future.State
state()

Overrides default java.util.concurrent.Future.state.

Returns the computation state.

public static <
the function's return type
U
>
CompletableFuture<U>

Returns:

the new CompletableFuture
supplyAsync
(Supplier<U>
a function returning the value to be used to complete the returned CompletableFuture
supplier
)

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.

public static <
the function's return type
U
>
CompletableFuture<U>

Returns:

the new CompletableFuture
supplyAsync
(Supplier<U>
a function returning the value to be used to complete the returned CompletableFuture
supplier
,
Executor
the executor to use for asynchronous execution
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.

public CompletableFuture<Void>
thenAccept(Consumer<? super T>
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.thenAccept.

Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action.

public CompletableFuture<Void>
thenAcceptAsync(Consumer<? super T>
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.thenAcceptAsync.

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.

public CompletableFuture<Void>
thenAcceptAsync(Consumer<? super T>
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.thenAcceptAsync.

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.

public <U> CompletableFuture<Void>
thenAcceptBoth(CompletionStage<? extends U>
the other CompletionStage
other
,
BiConsumer<? super T, ? super U>
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.thenAcceptBoth.

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.

public <U> CompletableFuture<Void>
thenAcceptBothAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiConsumer<? super T, ? super U>
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.thenAcceptBothAsync.

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.

public <U> CompletableFuture<Void>
thenAcceptBothAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiConsumer<? super T, ? super U>
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.thenAcceptBothAsync.

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.

public <U> CompletableFuture<U>
thenApply(Function<? super T, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.thenApply.

Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function.

public <U> CompletableFuture<U>
thenApplyAsync(Function<? super T, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.thenApplyAsync.

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.

public <U> CompletableFuture<U>
thenApplyAsync(Function<? super T, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.thenApplyAsync.

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.

public <U, V> CompletableFuture<V>
thenCombine(CompletionStage<? extends U>
the other CompletionStage
other
,
BiFunction<? super T, ? super U, ? extends V>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.thenCombine.

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.

public <U, V> CompletableFuture<V>
thenCombineAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiFunction<? super T, ? super U, ? extends V>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.thenCombineAsync.

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.

public <U, V> CompletableFuture<V>
thenCombineAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiFunction<? super T, ? super U, ? extends V>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.thenCombineAsync.

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.

public <U> CompletableFuture<U>
thenCompose(Function<? super T, ? extends CompletionStage<U>>
the function to use to compute another CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.thenCompose.

Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function.

public <U> CompletableFuture<U>
thenComposeAsync(Function<? super T, ? extends CompletionStage<U>>
the function to use to compute another CompletionStage
fn
)

Implements java.util.concurrent.CompletionStage.thenComposeAsync.

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.

public <U> CompletableFuture<U>
thenComposeAsync(Function<? super T, ? extends CompletionStage<U>>
the function to use to compute another CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.thenComposeAsync.

Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor.

public CompletableFuture<Void>
thenRun(Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.thenRun.

Returns a new CompletionStage that, when this stage completes normally, executes the given action.

public CompletableFuture<Void>
thenRunAsync(Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements java.util.concurrent.CompletionStage.thenRunAsync.

Returns a new CompletionStage that, when this stage completes normally, executes the given action using this stage's default asynchronous execution facility.

public CompletableFuture<Void>
thenRunAsync(Runnable
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.thenRunAsync.

Returns a new CompletionStage that, when this stage completes normally, executes the given action using the supplied Executor.

private Object
timedGet(long nanos)

Returns raw result after waiting, or null if interrupted, or throws TimeoutException on timeout.

public CompletableFuture<T>

Returns:

this CompletableFuture
toCompletableFuture
()

Implements java.util.concurrent.CompletionStage.toCompletableFuture.

Returns this CompletableFuture.

public String

Returns:

a string identifying this CompletableFuture, as well as its state
toString
()

Overrides java.lang.Object.toString.

Returns a string identifying this CompletableFuture, as well as its completion state.

pack-priv final boolean
tryPushStack(CompletableFuture.Completion c)

Returns true if successfully pushed c onto stack.

private CompletableFuture<Void>
uniAcceptNow(Object r, Executor e, Consumer<? super T> f)

private CompletableFuture<Void>
uniAcceptStage(Executor e, Consumer<? super T> f)

private <V> CompletableFuture<V>
uniApplyNow(Object r, Executor e, Function<? super T, ? extends V> f)

private <V> CompletableFuture<V>
uniApplyStage(Executor e, Function<? super T, ? extends V> f)

private CompletableFuture.MinimalStage<T>
private CompletableFuture<T>
private <V> CompletableFuture<V>
uniComposeStage(Executor e, Function<? super T, ? extends CompletionStage<V>> f)

private static <U, T extends U> CompletableFuture<U>
pack-priv final boolean
private CompletableFuture<T>
pack-priv final <S> boolean
uniHandle(Object r, BiFunction<? super S, Throwable, ? extends T> f, CompletableFuture.UniHandle<S, T> c)

private <V> CompletableFuture<V>
uniHandleStage(Executor e, BiFunction<? super T, Throwable, ? extends V> f)

pack-priv final void
unipush(CompletableFuture.Completion c)

Pushes the given completion unless it completes while trying.

private CompletableFuture<Void>
private CompletableFuture<Void>
pack-priv final boolean
private CompletableFuture<T>
private Object
waitingGet(boolean interruptible)

Returns raw result after waiting, or null if interruptible and interrupted.

public CompletableFuture<T>
whenComplete(BiConsumer<? super T, ? super Throwable>
the action to perform
action
)

Implements java.util.concurrent.CompletionStage.whenComplete.

Returns a new CompletionStage with the same result or exception as this stage, that executes the given action when this stage completes.

public CompletableFuture<T>
whenCompleteAsync(BiConsumer<? super T, ? super Throwable>
the action to perform
action
)

Implements java.util.concurrent.CompletionStage.whenCompleteAsync.

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.

public CompletableFuture<T>
whenCompleteAsync(BiConsumer<? super T, ? super Throwable>
the action to perform
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements java.util.concurrent.CompletionStage.whenCompleteAsync.

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.

pack-priv static CompletionException
pack-priv static ExecutionException
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait