public interface Future<T> extends AsyncResult<T>
| Modifier and Type | Field and Description |
|---|---|
static FutureFactory |
factory |
| Modifier and Type | Method and Description |
|---|---|
Throwable |
cause()
A Throwable describing failure.
|
default <U> Future<U> |
compose(java.util.function.Function<T,Future<U>> mapper)
Compose this future with a
mapper function. |
boolean |
failed()
Did it fail?
|
static <T> Future<T> |
failedFuture(String failureMessage)
Create a failed future with the specified failure message.
|
static <T> Future<T> |
failedFuture(Throwable t)
Create a failed future with the specified failure cause.
|
static <T> Future<T> |
future(Handler<Promise<T>> handler)
Create a future that hasn't completed yet and that is passed to the
handler before it is returned. |
Handler<AsyncResult<T>> |
getHandler() |
boolean |
isComplete()
Has the future completed?
|
default <U> Future<U> |
map(java.util.function.Function<T,U> mapper)
Apply a
mapper function on this future. |
default <V> Future<V> |
map(V value)
Map the result of a future to a specific
value. |
default <V> Future<V> |
mapEmpty()
Map the result of a future to
null. |
default Future<T> |
otherwise(java.util.function.Function<Throwable,T> mapper)
Apply a
mapper function on this future. |
default Future<T> |
otherwise(T value)
Map the failure of a future to a specific
value. |
default Future<T> |
otherwiseEmpty()
Map the failure of a future to
null. |
default Future<T> |
recover(java.util.function.Function<Throwable,Future<T>> mapper)
Handles a failure of this Future by returning the result of another Future.
|
T |
result()
The result of the operation.
|
Future<T> |
setHandler(Handler<AsyncResult<T>> handler)
Set a handler for the result.
|
boolean |
succeeded()
Did it succeed?
|
static <T> Future<T> |
succeededFuture()
Create a succeeded future with a null result
|
static <T> Future<T> |
succeededFuture(T result)
Created a succeeded future with the specified result.
|
static final FutureFactory factory
static <T> Future<T> future(Handler<Promise<T>> handler)
handler before it is returned.T - the result typehandler - the handlerstatic <T> Future<T> succeededFuture()
T - the result typestatic <T> Future<T> succeededFuture(T result)
T - the result typeresult - the resultstatic <T> Future<T> failedFuture(Throwable t)
T - the result typet - the failure cause as a Throwablestatic <T> Future<T> failedFuture(String failureMessage)
T - the result typefailureMessage - the failure messageboolean isComplete()
It's completed if it's either succeeded or failed.
Future<T> setHandler(Handler<AsyncResult<T>> handler)
If the future has already been completed it will be called immediately. Otherwise it will be called when the future is completed.
handler - the Handler that will be called with the resultHandler<AsyncResult<T>> getHandler()
T result()
result in interface AsyncResult<T>Throwable cause()
cause in interface AsyncResult<T>boolean succeeded()
succeeded in interface AsyncResult<T>boolean failed()
failed in interface AsyncResult<T>default <U> Future<U> compose(java.util.function.Function<T,Future<U>> mapper)
mapper function.
When this future (the one on which compose is called) succeeds, the mapper will be called with
the completed value and this mapper returns another future object. This returned future completion will complete
the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the returned future and the mapper
will not be called.
mapper - the mapper functiondefault <U> Future<U> map(java.util.function.Function<T,U> mapper)
mapper function on this future.
When this future succeeds, the mapper will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the returned future and the mapper
will not be called.
map in interface AsyncResult<T>mapper - the mapper functiondefault <V> Future<V> map(V value)
value.
When this future succeeds, this value will complete the future returned by this method call.
When this future fails, the failure will be propagated to the returned future.
map in interface AsyncResult<T>value - the value that eventually completes the mapped futuredefault <V> Future<V> mapEmpty()
null.
This is a conveniency for future.map((T) null) or future.map((Void) null).
When this future succeeds, null will complete the future returned by this method call.
When this future fails, the failure will be propagated to the returned future.
mapEmpty in interface AsyncResult<T>default Future<T> recover(java.util.function.Function<Throwable,Future<T>> mapper)
mapper - A function which takes the exception of a failure and returns a new future.default Future<T> otherwise(java.util.function.Function<Throwable,T> mapper)
mapper function on this future.
When this future fails, the mapper will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper throws an exception, the returned future will be failed with this exception.
When this future succeeds, the result will be propagated to the returned future and the mapper
will not be called.
otherwise in interface AsyncResult<T>mapper - the mapper functiondefault Future<T> otherwise(T value)
value.
When this future fails, this value will complete the future returned by this method call.
When this future succeeds, the result will be propagated to the returned future.
otherwise in interface AsyncResult<T>value - the value that eventually completes the mapped futuredefault Future<T> otherwiseEmpty()
null.
This is a convenience for future.otherwise((T) null).
When this future fails, the null value will complete the future returned by this method call.
When this future succeeds, the result will be propagated to the returned future.
otherwiseEmpty in interface AsyncResult<T>Copyright © 2019 Eclipse. All rights reserved.