Interface Future<T>
- All Superinterfaces:
AsyncResult<T>
- All Known Subinterfaces:
CompositeFuture,FutureInternal<T>,PromiseInternal<T>
- All Known Implementing Classes:
CompositeFutureImpl,FailedFuture,FutureImpl,PromiseImpl,SucceededFuture
- Author:
- Tim Fox
-
Method Summary
Modifier and TypeMethodDescriptionstatic CompositeFutureReturn a composite future, succeeded when all futures are succeeded, failed when any future is failed.static CompositeFutureLikeall(Future, Future)but with 3 futures.static CompositeFutureLikeall(Future, Future)but with 4 futures.static CompositeFutureLikeall(Future, Future)but with 5 futures.static CompositeFutureLikeall(Future, Future)but with 6 futures.static CompositeFutureLikeall(Future, Future)but with a list of futures.andThen(Handler<AsyncResult<T>> handler) Invokes the givenhandlerupon completion.static CompositeFutureReturn a composite future, succeeded when any futures is succeeded, failed when all futures are failed.static CompositeFutureLikeany(Future, Future)but with 3 futures.static CompositeFutureLikeany(Future, Future)but with 4 futures.static CompositeFutureLikeany(Future, Future)but with 5 futures.static CompositeFutureLikeany(Future, Future)but with 6 futures.static CompositeFutureLikeany(Future, Future)but with a list of futures.cause()A Throwable describing failure.default <U> Future<U>Compose this future with amapperfunction.<U> Future<U>Compose this future with asuccessMapperandfailureMapperfunctions.eventually(Function<Void, Future<U>> function) Deprecated.eventually(Supplier<Future<U>> supplier) Compose this future with asupplierthat will be always be called.booleanfailed()Did it fail?static <T> Future<T>failedFuture(String failureMessage) Create a failed future with the specified failure message.static <T> Future<T>Create a failed future with the specified failure cause.default <U> Future<U>Alias forcompose(Function).static <T> Future<T>Create a future that hasn't completed yet and that is passed to thehandlerbefore it is returned.booleanHas the future completed?static CompositeFutureReturn a composite future, succeeded when all futures are succeeded, failed when any future is failed.static CompositeFutureLikejoin(Future, Future)but with 3 futures.static CompositeFutureLikejoin(Future, Future)but with 4 futures.static CompositeFutureLikejoin(Future, Future)but with 5 futures.static CompositeFutureLikejoin(Future, Future)but with 6 futures.static CompositeFutureLikejoin(Future, Future)but with a list of futures.<U> Future<U>Apply amapperfunction on this future.<V> Future<V>map(V value) Map the result of a future to a specificvalue.default <V> Future<V>mapEmpty()Map the result of a future tonull.onComplete(Handler<AsyncResult<T>> handler) Add a handler to be notified of the result.onComplete(Handler<T> successHandler, Handler<Throwable> failureHandler) Add handlers to be notified on succeeded result and failed result.Add a handler to be notified of the failed result.Add a handler to be notified of the succeeded result.Apply amapperfunction on this future.Map the failure of a future to a specificvalue.Map the failure of a future tonull.Handles a failure of this Future by returning the result of another Future.result()The result of the operation.booleanDid it succeed?static <T> Future<T>Create a succeeded future with a null resultstatic <T> Future<T>succeededFuture(T result) Created a succeeded future with the specified result.<U> Future<U>transform(Function<AsyncResult<T>, Future<U>> mapper) Transform this future with amapperfunctions.
-
Method Details
-
all
Return a composite future, succeeded when all futures are succeeded, failed when any future is failed. The returned future fails as soon as one off1orf2fails.- Parameters:
f1- futuref2- future- Returns:
- the composite future
-
all
Likeall(Future, Future)but with 3 futures. -
all
Likeall(Future, Future)but with 4 futures. -
all
Likeall(Future, Future)but with 5 futures. -
all
static CompositeFuture all(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5, Future<?> f6) Likeall(Future, Future)but with 6 futures. -
all
Likeall(Future, Future)but with a list of futures.When the list is empty, the returned future will be already completed.
-
any
Return a composite future, succeeded when any futures is succeeded, failed when all futures are failed. The returned future succeeds as soon as one off1orf2succeeds.- Parameters:
f1- futuref2- future- Returns:
- the composite future
-
any
Likeany(Future, Future)but with 3 futures. -
any
Likeany(Future, Future)but with 4 futures. -
any
Likeany(Future, Future)but with 5 futures. -
any
static CompositeFuture any(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5, Future<?> f6) Likeany(Future, Future)but with 6 futures. -
any
Likeany(Future, Future)but with a list of futures.When the list is empty, the returned future will be already completed.
-
join
Return a composite future, succeeded when all futures are succeeded, failed when any future is failed. It always wait until all its futures are completed and will not fail as soon as one off1orf2fails.- Parameters:
f1- futuref2- future- Returns:
- the composite future
-
join
Likejoin(Future, Future)but with 3 futures. -
join
Likejoin(Future, Future)but with 4 futures. -
join
Likejoin(Future, Future)but with 5 futures. -
join
static CompositeFuture join(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5, Future<?> f6) Likejoin(Future, Future)but with 6 futures. -
join
Likejoin(Future, Future)but with a list of futures.When the list is empty, the returned future will be already completed.
-
future
Create a future that hasn't completed yet and that is passed to thehandlerbefore it is returned.- Type Parameters:
T- the result type- Parameters:
handler- the handler- Returns:
- the future.
-
succeededFuture
Create a succeeded future with a null result- Type Parameters:
T- the result type- Returns:
- the future
-
succeededFuture
Created a succeeded future with the specified result.- Type Parameters:
T- the result type- Parameters:
result- the result- Returns:
- the future
-
failedFuture
Create a failed future with the specified failure cause.- Type Parameters:
T- the result type- Parameters:
t- the failure cause as a Throwable- Returns:
- the future
-
failedFuture
Create a failed future with the specified failure message.- Type Parameters:
T- the result type- Parameters:
failureMessage- the failure message- Returns:
- the future
-
isComplete
boolean isComplete()Has the future completed?It's completed if it's either succeeded or failed.
- Returns:
- true if completed, false if not
-
onComplete
Add a handler to be notified of the result.WARNING: this is a terminal operation. If several
handlers are registered, there is no guarantee that they will be invoked in order of registration.- Parameters:
handler- the handler that will be called with the result- Returns:
- a reference to this, so it can be used fluently
-
onComplete
Add handlers to be notified on succeeded result and failed result.WARNING: this is a terminal operation. If several
handlers are registered, there is no guarantee that they will be invoked in order of registration.- Parameters:
successHandler- the handler that will be called with the succeeded resultfailureHandler- the handler that will be called with the failed result- Returns:
- a reference to this, so it can be used fluently
-
onSuccess
Add a handler to be notified of the succeeded result.WARNING: this is a terminal operation. If several
handlers are registered, there is no guarantee that they will be invoked in order of registration.- Parameters:
handler- the handler that will be called with the succeeded result- Returns:
- a reference to this, so it can be used fluently
-
onFailure
Add a handler to be notified of the failed result.WARNING: this is a terminal operation. If several
handlers are registered, there is no guarantee that they will be invoked in order of registration.- Parameters:
handler- the handler that will be called with the failed result- Returns:
- a reference to this, so it can be used fluently
-
result
T result()The result of the operation. This will be null if the operation failed.- Specified by:
resultin interfaceAsyncResult<T>- Returns:
- the result or null if the operation failed.
-
cause
Throwable cause()A Throwable describing failure. This will be null if the operation succeeded.- Specified by:
causein interfaceAsyncResult<T>- Returns:
- the cause or null if the operation succeeded.
-
succeeded
boolean succeeded()Did it succeed?- Specified by:
succeededin interfaceAsyncResult<T>- Returns:
- true if it succeded or false otherwise
-
failed
boolean failed()Did it fail?- Specified by:
failedin interfaceAsyncResult<T>- Returns:
- true if it failed or false otherwise
-
flatMap
Alias forcompose(Function). -
compose
Compose this future with amapperfunction.When this future (the one on which
composeis called) succeeds, themapperwill 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
mapperthrows 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
mapperwill not be called.- Parameters:
mapper- the mapper function- Returns:
- the composed future
-
recover
Handles a failure of this Future by returning the result of another Future. If the mapper fails, then the returned future will be failed with this failure.- Parameters:
mapper- A function which takes the exception of a failure and returns a new future.- Returns:
- A recovered future
-
compose
<U> Future<U> compose(Function<T, Future<U>> successMapper, Function<Throwable, Future<U>> failureMapper) Compose this future with asuccessMapperandfailureMapperfunctions.When this future (the one on which
composeis called) succeeds, thesuccessMapperwill 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.When this future (the one on which
composeis called) fails, thefailureMapperwill be called with the failure and this mapper returns another future object. This returned future completion will complete the future returned by this method call.If any mapper function throws an exception, the returned future will be failed with this exception.
- Parameters:
successMapper- the function mapping the successfailureMapper- the function mapping the failure- Returns:
- the composed future
-
transform
Transform this future with amapperfunctions.When this future (the one on which
transformis called) completes, themapperwill be called with the async result and this mapper returns another future object. This returned future completion will complete the future returned by this method call.If any mapper function throws an exception, the returned future will be failed with this exception.
- Parameters:
mapper- the function mapping the future- Returns:
- the transformed future
-
eventually
Deprecated.instead useeventually(Supplier), this method will be removed in Vert.x 5Compose this future with afunctionthat will be always be called.When this future (the one on which
eventuallyis called) completes, thefunctionwill be called and this mapper returns another future object. This returned future completion will complete the future returned by this method call with the original result of the future.The outcome of the future returned by the
functionwill not influence the nature of the returned future.- Parameters:
function- the function returning the future.- Returns:
- the composed future
-
eventually
Compose this future with asupplierthat will be always be called.When this future (the one on which
eventuallyis called) completes, thesupplierwill be called and this mapper returns another future object. This returned future completion will complete the future returned by this method call with the original result of the future.The outcome of the future returned by the
supplierwill not influence the nature of the returned future.- Parameters:
supplier- the function returning the future.- Returns:
- the composed future
-
map
Apply amapperfunction on this future.When this future succeeds, the
mapperwill 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
mapperthrows 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
mapperwill not be called.- Specified by:
mapin interfaceAsyncResult<T>- Parameters:
mapper- the mapper function- Returns:
- the mapped future
-
map
Map the result of a future to a specificvalue.When this future succeeds, this
valuewill complete the future returned by this method call.When this future fails, the failure will be propagated to the returned future.
- Specified by:
mapin interfaceAsyncResult<T>- Parameters:
value- the value that eventually completes the mapped future- Returns:
- the mapped future
-
mapEmpty
Map the result of a future tonull.This is a conveniency for
future.map((T) null)orfuture.map((Void) null).When this future succeeds,
nullwill complete the future returned by this method call.When this future fails, the failure will be propagated to the returned future.
- Specified by:
mapEmptyin interfaceAsyncResult<T>- Returns:
- the mapped future
-
otherwise
Apply amapperfunction on this future.When this future fails, the
mapperwill 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
mapperthrows 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
mapperwill not be called.- Specified by:
otherwisein interfaceAsyncResult<T>- Parameters:
mapper- the mapper function- Returns:
- the mapped future
-
otherwise
Map the failure of a future to a specificvalue.When this future fails, this
valuewill complete the future returned by this method call.When this future succeeds, the result will be propagated to the returned future.
- Specified by:
otherwisein interfaceAsyncResult<T>- Parameters:
value- the value that eventually completes the mapped future- Returns:
- the mapped future
-
otherwiseEmpty
Map the failure of a future tonull.This is a convenience for
future.otherwise((T) null).When this future fails, the
nullvalue will complete the future returned by this method call.When this future succeeds, the result will be propagated to the returned future.
- Specified by:
otherwiseEmptyin interfaceAsyncResult<T>- Returns:
- the mapped future
-
andThen
Invokes the givenhandlerupon completion.If the
handlerthrows an exception, the returned future will be failed with this exception.- Parameters:
handler- invoked upon completion of this future- Returns:
- a future completed after the
handlerhas been invoked
-
eventually(Supplier), this method will be removed in Vert.x 5