-
- Type Parameters:
V
- the value type.
- All Superinterfaces:
CompletionStage<V>
,Future<V>
- All Known Implementing Classes:
DefaultPromise
public interface FutureCompletionStage<V> extends CompletionStage<V>, Future<V>
ACompletionStage
that provides the same threading semantics and guarantees as the underlyingFuture
, which means that all the callbacks will be executed byexecutor()
if not specified otherwise (by calling the corresponding *Async methods).This interface also extends
Future
, to provide blocking methods for awaiting the result of the future. This is in contrast to the NettyFuture
, which is entirely non-blocking.Please be aware that
toCompletableFuture()
is not supported and so will throw anUnsupportedOperationException
when invoked.
-
-
Method Summary
-
-
-
Method Detail
-
sync
FutureCompletionStage<V> sync() throws InterruptedException
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.- Throws:
CancellationException
- if the computation was cancelledCompletionException
- if the computation threw an exception.InterruptedException
- if the current thread was interrupted while waiting
-
join
default <T> T join(BiFunction<V,Throwable,T> resultHandler) throws InterruptedException
Waits for the future to complete, then calls the given result handler with the outcome.If the future completes successfully, then the result handler is called with the result of the future - which may be
null
- and anull
exception.If the future fails, then the result handler is called with a
null
result, and a non-null
exception.Success or failure of the future can be determined on whether the exception is
null
or not.The result handler may compute a new result, which will be the return value of the
join
call.- Type Parameters:
T
- The return type of theresultHandler
.- Parameters:
resultHandler
- The function that will process the result of the completed future.- Returns:
- The result of the
resultHandler
computation. - Throws:
InterruptedException
- if the thread is interrupted while waiting for the future to complete.
-
await
FutureCompletionStage<V> await() throws InterruptedException
Waits for this future to be completed.- Throws:
InterruptedException
- if the current thread was interrupted
-
await
boolean await(long timeout, TimeUnit unit) throws InterruptedException
Waits for this future to be completed within the specified time limit.- Returns:
true
if and only if the future was completed within the specified time limit- Throws:
InterruptedException
- if the current thread was interrupted
-
getCause
default Throwable getCause() throws InterruptedException
Wait for the future to complete, and return the cause if it failed, ornull
if it succeeded.- Returns:
- The exception that caused the future to fail, if any, or
null
. - Throws:
InterruptedException
- if the current thread was interrupted while waiting.
-
future
Future<V> future()
Returns the underlyingFuture
of thisFutureCompletionStage
.
-
cancel
default boolean cancel()
-
isSuccess
default boolean isSuccess()
-
isFailed
default boolean isFailed()
-
isCancellable
default boolean isCancellable()
-
getNow
default V getNow()
-
cause
default Throwable cause()
-
executor
default EventExecutor executor()
-
toCompletableFuture
default CompletableFuture<V> toCompletableFuture()
Not supported and so throws anUnsupportedOperationException
.- Specified by:
toCompletableFuture
in interfaceCompletionStage<V>
-
thenApply
<U> FutureCompletionStage<U> thenApply(Function<? super V,? extends U> fn)
- Specified by:
thenApply
in interfaceCompletionStage<V>
-
thenApplyAsync
<U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
-
thenAccept
FutureCompletionStage<Void> thenAccept(Consumer<? super V> action)
- Specified by:
thenAccept
in interfaceCompletionStage<V>
-
thenAcceptAsync
FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
-
thenRun
FutureCompletionStage<Void> thenRun(Runnable action)
- Specified by:
thenRun
in interfaceCompletionStage<V>
-
thenRunAsync
FutureCompletionStage<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
-
thenCombine
<U,V1> FutureCompletionStage<V1> thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombine
in interfaceCompletionStage<V>
-
thenCombineAsync
<U,V1> FutureCompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombineAsync
in interfaceCompletionStage<V>
-
thenAcceptBoth
<U> FutureCompletionStage<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBoth
in interfaceCompletionStage<V>
-
thenAcceptBothAsync
<U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<V>
-
runAfterBoth
FutureCompletionStage<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBoth
in interfaceCompletionStage<V>
-
runAfterBothAsync
FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<V>
-
applyToEither
<U> FutureCompletionStage<U> applyToEither(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEither
in interfaceCompletionStage<V>
-
applyToEitherAsync
<U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<V>
-
acceptEither
FutureCompletionStage<Void> acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEither
in interfaceCompletionStage<V>
-
acceptEitherAsync
FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<V>
-
runAfterEither
FutureCompletionStage<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEither
in interfaceCompletionStage<V>
-
runAfterEitherAsync
FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
-
thenCompose
<U> FutureCompletionStage<U> thenCompose(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenCompose
in interfaceCompletionStage<V>
-
thenComposeAsync
<U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<V>
-
whenComplete
FutureCompletionStage<V> whenComplete(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenComplete
in interfaceCompletionStage<V>
-
whenCompleteAsync
FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<V>
-
handle
<U> FutureCompletionStage<U> handle(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handle
in interfaceCompletionStage<V>
-
handleAsync
<U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handleAsync
in interfaceCompletionStage<V>
-
thenApplyAsync
<U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
-
thenAcceptAsync
FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action, Executor executor)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
-
thenRunAsync
FutureCompletionStage<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
-
thenCombineAsync
<U,V1> FutureCompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn, Executor executor)
- Specified by:
thenCombineAsync
in interfaceCompletionStage<V>
-
thenAcceptBothAsync
<U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<V>
-
runAfterBothAsync
FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<V>
-
applyToEitherAsync
<U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn, Executor executor)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<V>
-
acceptEitherAsync
FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<V>
-
runAfterEitherAsync
FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
-
thenComposeAsync
<U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<V>
-
exceptionally
FutureCompletionStage<V> exceptionally(Function<Throwable,? extends V> fn)
- Specified by:
exceptionally
in interfaceCompletionStage<V>
-
whenCompleteAsync
FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<V>
-
handleAsync
<U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsync
in interfaceCompletionStage<V>
-
toFutureCompletionStage
static <U> FutureCompletionStage<U> toFutureCompletionStage(CompletionStage<U> stage, EventExecutor executor)
Returns aFutureCompletionStage
for the givenCompletionStage
that is pinned to the givenEventExecutor
.
-
isCancelled
boolean isCancelled()
Returntrue
if this operation has been cancelled.- Returns:
true
if this operation has been cancelled, otherwisefalse
.
-
isDone
boolean isDone()
Returntrue
if this operation has been completed either successfully, unsuccessfully, or through cancellation.- Returns:
true
if this operation has completed, otherwisefalse
.
-
-