public interface Future<T> extends AsyncResult<T>
Modifier and Type | Method and Description |
---|---|
static CompositeFuture |
all(Future<?> f1,
Future<?> f2)
Return a composite future, succeeded when all futures are succeeded, failed when any future is failed.
|
static CompositeFuture |
all(Future<?> f1,
Future<?> f2,
Future<?> f3)
Like
all(Future, Future) but with 3 futures. |
static CompositeFuture |
all(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4)
Like
all(Future, Future) but with 4 futures. |
static CompositeFuture |
all(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4,
Future<?> f5)
Like
all(Future, Future) but with 5 futures. |
static CompositeFuture |
all(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4,
Future<?> f5,
Future<?> f6)
Like
all(Future, Future) but with 6 futures. |
static CompositeFuture |
all(List<? extends Future<?>> futures)
Like
all(Future, Future) but with a list of futures. |
default Future<T> |
andThen(Handler<AsyncResult<T>> handler)
Invokes the given
handler upon completion. |
static CompositeFuture |
any(Future<?> f1,
Future<?> f2)
Return a composite future, succeeded when any futures is succeeded, failed when all futures are failed.
|
static CompositeFuture |
any(Future<?> f1,
Future<?> f2,
Future<?> f3)
Like
any(Future, Future) but with 3 futures. |
static CompositeFuture |
any(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4)
Like
any(Future, Future) but with 4 futures. |
static CompositeFuture |
any(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4,
Future<?> f5)
Like
any(Future, Future) but with 5 futures. |
static CompositeFuture |
any(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4,
Future<?> f5,
Future<?> f6)
Like
any(Future, Future) but with 6 futures. |
static CompositeFuture |
any(List<? extends Future<?>> futures)
Like
any(Future, Future) but with a list of futures. |
static <T> T |
await(Future<T> future)
Park the current thread until the
future is 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 virtual thread. |
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. |
<U> Future<U> |
compose(java.util.function.Function<T,Future<U>> successMapper,
java.util.function.Function<Throwable,Future<U>> failureMapper)
Compose this future with a
successMapper and failureMapper functions. |
<U> Future<T> |
eventually(java.util.function.Function<Void,Future<U>> function)
Deprecated.
instead use
eventually(Supplier) , this method will be removed in Vert.x 5 |
default <U> Future<T> |
eventually(java.util.function.Supplier<Future<U>> supplier)
Compose this future with a
supplier that will be always be called. |
Future<T> |
expecting(Expectation<? super T> expectation)
Guard the control flow of this future with an expectation.
|
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.
|
default <U> Future<U> |
flatMap(java.util.function.Function<T,Future<U>> mapper)
Alias for
compose(Function) . |
static <T> Future<T> |
fromCompletionStage(CompletionStage<T> completionStage)
Bridges a
CompletionStage object to a Vert.x future instance. |
static <T> Future<T> |
fromCompletionStage(CompletionStage<T> completionStage,
Context context)
Bridges a
CompletionStage object to a Vert.x future instance. |
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. |
boolean |
isComplete()
Has the future completed?
|
static CompositeFuture |
join(Future<?> f1,
Future<?> f2)
Return a composite future, succeeded when all futures are succeeded, failed when any future is failed.
|
static CompositeFuture |
join(Future<?> f1,
Future<?> f2,
Future<?> f3)
Like
join(Future, Future) but with 3 futures. |
static CompositeFuture |
join(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4)
Like
join(Future, Future) but with 4 futures. |
static CompositeFuture |
join(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4,
Future<?> f5)
Like
join(Future, Future) but with 5 futures. |
static CompositeFuture |
join(Future<?> f1,
Future<?> f2,
Future<?> f3,
Future<?> f4,
Future<?> f5,
Future<?> f6)
Like
join(Future, Future) but with 6 futures. |
static CompositeFuture |
join(List<? extends Future<?>> futures)
Like
join(Future, Future) but with a list of futures. |
<U> Future<U> |
map(java.util.function.Function<T,U> mapper)
Apply a
mapper function on this future. |
<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 . |
Future<T> |
onComplete(Handler<AsyncResult<T>> handler)
Add a handler to be notified of the result.
|
default Future<T> |
onComplete(Handler<T> successHandler,
Handler<Throwable> failureHandler)
Add handlers to be notified on succeeded result and failed result.
|
default Future<T> |
onFailure(Handler<Throwable> handler)
Add a handler to be notified of the failed result.
|
default Future<T> |
onSuccess(Handler<T> handler)
Add a handler to be notified of the succeeded result.
|
Future<T> |
otherwise(java.util.function.Function<Throwable,T> mapper)
Apply a
mapper function on this future. |
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.
|
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.
|
Future<T> |
timeout(long delay,
TimeUnit unit)
Returns a future succeeded or failed with the outcome of this future when it happens before the timeout fires.
|
default CompletionStage<T> |
toCompletionStage()
Bridges this Vert.x future to a
CompletionStage instance. |
<U> Future<U> |
transform(java.util.function.Function<AsyncResult<T>,Future<U>> mapper)
Transform this future with a
mapper functions. |
static CompositeFuture all(Future<?> f1, Future<?> f2)
f1
or f2
fails.f1
- futuref2
- futurestatic CompositeFuture all(Future<?> f1, Future<?> f2, Future<?> f3)
all(Future, Future)
but with 3 futures.static CompositeFuture all(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4)
all(Future, Future)
but with 4 futures.static CompositeFuture all(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5)
all(Future, Future)
but with 5 futures.static CompositeFuture all(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5, Future<?> f6)
all(Future, Future)
but with 6 futures.static CompositeFuture all(List<? extends Future<?>> futures)
all(Future, Future)
but with a list of futures.When the list is empty, the returned future will be already completed.
static CompositeFuture any(Future<?> f1, Future<?> f2)
f1
or f2
succeeds.f1
- futuref2
- futurestatic CompositeFuture any(Future<?> f1, Future<?> f2, Future<?> f3)
any(Future, Future)
but with 3 futures.static CompositeFuture any(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4)
any(Future, Future)
but with 4 futures.static CompositeFuture any(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5)
any(Future, Future)
but with 5 futures.static CompositeFuture any(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5, Future<?> f6)
any(Future, Future)
but with 6 futures.static CompositeFuture any(List<? extends Future<?>> futures)
any(Future, Future)
but with a list of futures.When the list is empty, the returned future will be already completed.
static CompositeFuture join(Future<?> f1, Future<?> f2)
f1
or f2
fails.f1
- futuref2
- futurestatic CompositeFuture join(Future<?> f1, Future<?> f2, Future<?> f3)
join(Future, Future)
but with 3 futures.static CompositeFuture join(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4)
join(Future, Future)
but with 4 futures.static CompositeFuture join(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5)
join(Future, Future)
but with 5 futures.static CompositeFuture join(Future<?> f1, Future<?> f2, Future<?> f3, Future<?> f4, Future<?> f5, Future<?> f6)
join(Future, Future)
but with 6 futures.static CompositeFuture join(List<? extends Future<?>> futures)
join(Future, Future)
but with a list of futures.When the list is empty, the returned future will be already completed.
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> onComplete(Handler<AsyncResult<T>> handler)
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.
handler
- the handler that will be called with the resultdefault Future<T> onComplete(Handler<T> successHandler, Handler<Throwable> failureHandler)
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.
successHandler
- the handler that will be called with the succeeded resultfailureHandler
- the handler that will be called with the failed resultdefault Future<T> onSuccess(Handler<T> handler)
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.
handler
- the handler that will be called with the succeeded resultdefault Future<T> onFailure(Handler<Throwable> handler)
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.
handler
- the handler that will be called with the failed resultT 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> flatMap(java.util.function.Function<T,Future<U>> mapper)
compose(Function)
.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 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.<U> Future<U> compose(java.util.function.Function<T,Future<U>> successMapper, java.util.function.Function<Throwable,Future<U>> failureMapper)
successMapper
and failureMapper
functions.
When this future (the one on which compose
is called) succeeds, the successMapper
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, the failureMapper
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.
successMapper
- the function mapping the successfailureMapper
- the function mapping the failure<U> Future<U> transform(java.util.function.Function<AsyncResult<T>,Future<U>> mapper)
mapper
functions.
When this future (the one on which transform
is called) completes, the mapper
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.
mapper
- the function mapping the future@Deprecated <U> Future<T> eventually(java.util.function.Function<Void,Future<U>> function)
eventually(Supplier)
, this method will be removed in Vert.x 5function
that will be always be called.
When this future (the one on which eventually
is called) completes, the function
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.
function
- the function returning the future.default <U> Future<T> eventually(java.util.function.Supplier<Future<U>> supplier)
supplier
that will be always be called.
When this future (the one on which eventually
is called) completes, the supplier
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.
supplier
- the function returning the future.<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 function<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>
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 functionFuture<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>
default Future<T> andThen(Handler<AsyncResult<T>> handler)
handler
upon completion.
If the handler
throws an exception, the returned future will be failed with this exception.
handler
- invoked upon completion of this futurehandler
has been invokedFuture<T> expecting(Expectation<? super T> expectation)
expectation
is called with the result, when the expectation
returns false
the 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);
Expectation
instances can also be used:
future = future.expecting(HttpResponseExpectation.SC_OK);
expectation
- the expectationFuture<T> timeout(long delay, TimeUnit unit)
TimeoutException
, guaranteeing
the returned future to complete within the specified delay
.delay
- the delayunit
- the unit of the delaydefault CompletionStage<T> toCompletionStage()
CompletionStage
instance.
The CompletionStage
handling methods will be called from the thread that resolves this future.
CompletionStage
that completes when this future resolvesstatic <T> Future<T> fromCompletionStage(CompletionStage<T> completionStage)
CompletionStage
object to a Vert.x future instance.
The Vert.x future handling methods will be called from the thread that completes completionStage
.
T
- the result typecompletionStage
- a completion stagecompletionStage
resolvesstatic <T> Future<T> fromCompletionStage(CompletionStage<T> completionStage, Context context)
CompletionStage
object to a Vert.x future instance.
The Vert.x future handling methods will be called on the provided context
.
T
- the result typecompletionStage
- a completion stagecontext
- a Vert.x context to dispatch tocompletionStage
resolvesstatic <T> T await(Future<T> future)
future
is completed, when the future
is completed the thread is un-parked and
future
- the future to awaitIllegalStateException
- when called from an event-loop thread or a non Vert.x threadCopyright © 2024 Eclipse. All rights reserved.