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 CompositeFuture
Return a composite future, succeeded when all futures are succeeded, failed when any future is failed.static CompositeFuture
Likeall(Future, Future)
but with 3 futures.static CompositeFuture
Likeall(Future, Future)
but with 4 futures.static CompositeFuture
Likeall(Future, Future)
but with 5 futures.static CompositeFuture
Likeall(Future, Future)
but with 6 futures.static CompositeFuture
Likeall(Future, Future)
but with a list of futures.andThen
(Handler<AsyncResult<T>> handler) Invokes the givenhandler
upon completion.static CompositeFuture
Return a composite future, succeeded when any futures is succeeded, failed when all futures are failed.static CompositeFuture
Likeany(Future, Future)
but with 3 futures.static CompositeFuture
Likeany(Future, Future)
but with 4 futures.static CompositeFuture
Likeany(Future, Future)
but with 5 futures.static CompositeFuture
Likeany(Future, Future)
but with 6 futures.static CompositeFuture
Likeany(Future, Future)
but with a list of futures.cause()
A Throwable describing failure.default <U> Future<U>
Compose this future with amapper
function.<U> Future<U>
Compose this future with asuccessMapper
andfailureMapper
functions.eventually
(Function<Void, Future<U>> function) Deprecated.eventually
(Supplier<Future<U>> supplier) Compose this future with asupplier
that will be always be called.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>
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 thehandler
before it is returned.boolean
Has the future completed?static CompositeFuture
Return a composite future, succeeded when all futures are succeeded, failed when any future is failed.static CompositeFuture
Likejoin(Future, Future)
but with 3 futures.static CompositeFuture
Likejoin(Future, Future)
but with 4 futures.static CompositeFuture
Likejoin(Future, Future)
but with 5 futures.static CompositeFuture
Likejoin(Future, Future)
but with 6 futures.static CompositeFuture
Likejoin(Future, Future)
but with a list of futures.<U> Future<U>
Apply amapper
function 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 amapper
function 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.boolean
Did 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 amapper
functions.
-
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 off1
orf2
fails.- 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 off1
orf2
succeeds.- 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 off1
orf2
fails.- 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 thehandler
before 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
handler
s 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
handler
s 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
handler
s 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
handler
s 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:
result
in 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:
cause
in interfaceAsyncResult<T>
- Returns:
- the cause or null if the operation succeeded.
-
succeeded
boolean succeeded()Did it succeed?- Specified by:
succeeded
in interfaceAsyncResult<T>
- Returns:
- true if it succeded or false otherwise
-
failed
boolean failed()Did it fail?- Specified by:
failed
in interfaceAsyncResult<T>
- Returns:
- true if it failed or false otherwise
-
flatMap
Alias forcompose(Function)
. -
compose
Compose this future with amapper
function.When this future (the one on which
compose
is called) succeeds, themapper
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.- 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 asuccessMapper
andfailureMapper
functions.When this future (the one on which
compose
is called) succeeds, thesuccessMapper
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.When this future (the one on which
compose
is called) fails, thefailureMapper
will 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 amapper
functions.When this future (the one on which
transform
is called) completes, themapper
will 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 afunction
that will be always be called.When this future (the one on which
eventually
is called) completes, thefunction
will 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
function
will not influence the nature of the returned future.- Parameters:
function
- the function returning the future.- Returns:
- the composed future
-
eventually
Compose this future with asupplier
that will be always be called.When this future (the one on which
eventually
is called) completes, thesupplier
will 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
supplier
will not influence the nature of the returned future.- Parameters:
supplier
- the function returning the future.- Returns:
- the composed future
-
map
Apply amapper
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.- Specified by:
map
in 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
value
will complete the future returned by this method call.When this future fails, the failure will be propagated to the returned future.
- Specified by:
map
in 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,
null
will complete the future returned by this method call.When this future fails, the failure will be propagated to the returned future.
- Specified by:
mapEmpty
in interfaceAsyncResult<T>
- Returns:
- the mapped future
-
otherwise
Apply amapper
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.- Specified by:
otherwise
in 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
value
will complete the future returned by this method call.When this future succeeds, the result will be propagated to the returned future.
- Specified by:
otherwise
in 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
null
value will complete the future returned by this method call.When this future succeeds, the result will be propagated to the returned future.
- Specified by:
otherwiseEmpty
in interfaceAsyncResult<T>
- Returns:
- the mapped future
-
andThen
Invokes the givenhandler
upon completion.If the
handler
throws 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
handler
has been invoked
-
eventually(Supplier)
, this method will be removed in Vert.x 5