T
- The type of the resultpublic class Future<T> extends Object implements Future<T>
Future
and
represents the result of an asynchronous computation.
Promise
and Future are two complementary concepts. They are designed
to synchronize data between multiples threads. The Future holds the result of
an asynchronous computation, from which you can retrieve the value of the
result; the Promise
sets the value of this computation, which
resolves the associated Future.
Modifier and Type | Class and Description |
---|---|
static interface |
Future.Callback<T> |
Modifier and Type | Method and Description |
---|---|
<R> Future<R> |
andThenApply(Function<T,R> function)
Launch a task when the task link when this future succeed only
|
<R> Future<R> |
andThenCompose(Function<T,Future<R>> function)
Launch a task when the task link when this future succeed only.
Instead of return a Future |
Future<Void> |
andThenConsume(Consumer<T> consumer)
Launch a task when the task link when this future succeed only
|
boolean |
cancel()
Deprecated.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
static <T> Future<T> |
cancelled() |
void |
connect(Future.Callback<T> callback) |
void |
connect(Future.Callback<T> callback,
FutureCallbackType futureCallbackType)
Prefer
#then(FutureFunction, FutureCallbackType) instead (e.g. |
protected void |
finalize()
Called by garbage collector Finalize is overridden to manually delete C++
data
|
static <T> Future<T> |
fromError(String errorMessage) |
T |
get() |
T |
get(long timeout,
TimeUnit unit) |
ExecutionException |
getError() |
String |
getErrorMessage() |
T |
getValue()
Same as
get() , but does not throw checked exceptions. |
boolean |
hasError() |
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isSuccess() |
static <T> Future<T> |
of(T value) |
void |
requestCancellation()
Sends asynchronously a request to cancel the execution of this task.
|
void |
sync() |
void |
sync(long timeout,
TimeUnit unit) |
<R> Future<R> |
thenApply(Function<Future<T>,R> function)
Launch a task when the task link when this future finished (succeed,
error or cancelled)
|
<R> Future<R> |
thenCompose(Function<Future<T>,Future<R>> function)
Launch a task when the task link when this future finished (succeed,
error or cancelled).
Instead of return a Future |
Future<Void> |
thenConsume(Consumer<Future<T>> consumer)
Launch a task when the task link when this future finished (succeed,
error or cancelled)
|
static Future<Void> |
waitAll(Future<?>... futures)
Wait for all
futures to complete. |
Future<T> |
waitFor(Future<?>... futures)
Return a version of
this future that waits until futures
to finish. |
public static <T> Future<T> of(T value)
public static <T> Future<T> cancelled()
public void sync(long timeout, TimeUnit unit)
public void sync()
public void connect(Future.Callback<T> callback, FutureCallbackType futureCallbackType)
#then(FutureFunction, FutureCallbackType)
instead (e.g.public void connect(Future.Callback<T> callback)
public boolean cancel(boolean mayInterruptIfRunning)
public void requestCancellation()
@Deprecated public boolean cancel()
public T get() throws ExecutionException
get
in interface Future<T>
ExecutionException
public T get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException
get
in interface Future<T>
ExecutionException
TimeoutException
public T getValue()
get()
, but does not throw checked exceptions.
This is especially useful for getting the value of a future that we know is complete with success.
public ExecutionException getError()
public boolean hasError()
public String getErrorMessage()
public boolean isCancelled()
isCancelled
in interface Future<T>
public boolean isSuccess()
public <R> Future<R> thenApply(Function<Future<T>,R> function)
R
- Function result typefunction
- Function to call when action the task link when this future
finishedpublic Future<Void> thenConsume(Consumer<Future<T>> consumer)
consumer
- Consumer to call when action the task link when this future
finishedpublic <R> Future<R> thenCompose(Function<Future<T>,Future<R>> function)
R
- Function result typefunction
- Function to call when action the task link when this future
finishedpublic <R> Future<R> andThenApply(Function<T,R> function)
R
- Function result typefunction
- Function to call when action the task link when this future
succeed onlypublic Future<Void> andThenConsume(Consumer<T> consumer)
consumer
- Consumer to call when action the task link when this future
succeed onlypublic <R> Future<R> andThenCompose(Function<T,Future<R>> function)
R
- Function result typefunction
- Function to call when action the task link when this future
succeed onlypublic static Future<Void> waitAll(Future<?>... futures)
futures
to complete.
The returning future finishes successfully if and only if all of the futures it waits for finish successfully.
Otherwise, it takes the state of the first failing future (due to cancellation or error).
futures
- the futures to wait forpublic Future<T> waitFor(Future<?>... futures)
this
future that waits until futures
to finish.
The returning future finishes successfully if and only if this
future and futures
finish successfully.
Otherwise, it takes the state of this
if it failed, or the first
failing future from futures
.
If this
future does not finish successfully, it does not wait for
futures
.
futures
- the futures to wait forfutures
are
finished successfullyCopyright © 2020. All rights reserved.