Interface Future<T>
- All Superinterfaces:
AsyncResult<T>
- All Known Subinterfaces:
CompositeFuture, Timer
- Author:
- Tim Fox
-
Method Summary
Modifier and TypeMethodDescriptionstatic CompositeFutureLikeall(Future, Future)but with a variable number of futures.static 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(Completable<? super T> handler) Invokes the givenhandlerupon completion.andThen(Handler<AsyncResult<T>> handler) Invokes the givenhandlerupon completion.static CompositeFutureLikeany(Future, Future)but with a variable number of futures.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.default Tawait()Park the current thread until thefutureis completed, when the future is completed the thread is un-parked and the result value is returned when the future was completed with a result otherwise, the failure is thrown This method must be called from a vertx virtual thread or a non vertx thread.default TLikeawait()but with a timeout.static <T> TCallsawait()onfuture.cause()A Throwable describing failure.default <U> Future<U> Compose this future with amapperfunction.<U> Future<U> Compose this future with asuccessMapperandfailureMapperfunctions.eventually(Supplier<Future<U>> mapper) Compose this future with amapperthat will be always be called.expecting(Expectation<? super T> expectation) Guard the control flow of this future with an expectation.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> fromCompletionStage(CompletionStage<T> completionStage) Bridges aCompletionStageobject to a Vert.x future instance.static <T> Future<T> fromCompletionStage(CompletionStage<T> completionStage, Context context) Bridges aCompletionStageobject to a Vert.x future instance.static <T> Future<T> Create a promise and pass it to thehandler, and then returns this future's promise.booleanHas the future completed?static CompositeFutureLikejoin(Future, Future)but with a variable number of futures.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(Completable<? super T> handler) Add handlers to be notified on succeeded result and failed result.onComplete(Handler<? super T> successHandler, Handler<? super Throwable> failureHandler) Add handlers to be notified on succeeded result and failed result.onComplete(Handler<AsyncResult<T>> handler) Add a handler to be notified of the 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.Returns a future succeeded or failed with the outcome of this future when it happens before the timeout fires.default CompletionStage<T> Bridges this Vert.x future to aCompletionStageinstance.default <U> Future<U> transform(BiFunction<? super T, ? super Throwable, Future<U>> mapper) Transform this future with amapperfunction.<U> Future<U> transform(Function<AsyncResult<T>, Future<U>> mapper) Transform this future with amapperfunction.
-
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 variable number of 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 variable number of futures. When the list is empty, the returned future will be already completed. -
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 variable number of futures. When the list is empty, the returned future will be already completed. -
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 promise and pass it to thehandler, and then returns this future's promise. Thehandleris responsible for completing the promise, if thehandlerthrows an exception, the promise is attempted to be failed with this exception.- Parameters:
handler- the handler completing the promise- Returns:
- the future of the created promise
-
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
-
failedFuture
-
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
default Future<T> onComplete(Handler<? super T> successHandler, Handler<? super Throwable> failureHandler) 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
-
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:
handler- the handler that will be called with the completion outcome- 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<? super 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 amapperfunction.When this future (the one on which
transformis called) completes, themapperwill be called with the async result returning another future instance. This returned future completion will complete the future returned by this method call.When
mapperthrows an exception, the returned future will be failed with this exception.- Parameters:
mapper- the function mapping the future- Returns:
- the transformed future
-
transform
Transform this future with amapperfunction.When this future (the one on which
transformis called) completes, themapperwill be called with the result/failure returning another future instance. This returned future completion will complete the future returned by this method call.When
mapperthrows an exception, the returned future will be failed with this exception.- Parameters:
mapper- the function mapping the future- Returns:
- the transformed future
-
eventually
Compose this future with amapperthat will be always be called.When this future (the one on which
eventuallyis called) completes, themapperwill 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
mapperwill not influence the nature of the returned future.- Parameters:
mapper- 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
-
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
-
expecting
Guard the control flow of this future with an expectation. When the future is completed with a success, theexpectationis called with the result, when the expectation returnsfalsethe returned future is failed, otherwise the future is completed with the same result. Expectations are usually lambda expressions:return future.expecting(response -> response.statusCode() == 200);
Expectationinstances can also be used:future = future.expecting(HttpResponseExpectation.SC_OK);
- Parameters:
expectation- the expectation- Returns:
- a future succeeded with the result or failed when the expectation returns false
-
timeout
Returns a future succeeded or failed with the outcome of this future when it happens before the timeout fires. When the timeout fires before, the future is failed with aTimeoutException, guaranteeing the returned future to complete within the specifieddelay.- Parameters:
delay- the delayunit- the unit of the delay- Returns:
- the timeout future
-
toCompletionStage
Bridges this Vert.x future to aCompletionStageinstance.The
CompletionStagehandling methods will be called from the thread that resolves this future.- Returns:
- a
CompletionStagethat completes when this future resolves
-
fromCompletionStage
Bridges aCompletionStageobject to a Vert.x future instance.The Vert.x future handling methods will be called from the thread that completes
completionStage.- Type Parameters:
T- the result type- Parameters:
completionStage- a completion stage- Returns:
- a Vert.x future that resolves when
completionStageresolves
-
fromCompletionStage
Bridges aCompletionStageobject to a Vert.x future instance.The Vert.x future handling methods will be called on the provided
context.- Type Parameters:
T- the result type- Parameters:
completionStage- a completion stagecontext- a Vert.x context to dispatch to- Returns:
- a Vert.x future that resolves when
completionStageresolves
-
await
Park the current thread until thefutureis completed, when the future is completed the thread is un-parked and- the result value is returned when the future was completed with a result
- otherwise, the failure is thrown
- Returns:
- the result
- Throws:
IllegalStateException- when called from a vertx event-loop or worker thread
-
await
Likeawait()but with a timeout.- Parameters:
timeout- the timeoutunit- the timeout unit- Returns:
- the result
- Throws:
TimeoutException- when the timeout fires before the future completesIllegalStateException- when called from a vertx event-loop or worker thread
-
await
Callsawait()onfuture.- Parameters:
future- the future to await- Returns:
- the result
- Throws:
IllegalStateException- when called from an event-loop thread or a non Vert.x thread
-