-
- 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>
ACompletionStagethat 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 anUnsupportedOperationExceptionwhen 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 anullexception.If the future fails, then the result handler is called with a
nullresult, and a non-nullexception.Success or failure of the future can be determined on whether the exception is
nullor not.The result handler may compute a new result, which will be the return value of the
joincall.- 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
resultHandlercomputation. - 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 InterruptedExceptionWaits for this future to be completed within the specified time limit.- Returns:
trueif 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, ornullif 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 underlyingFutureof 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:
toCompletableFuturein interfaceCompletionStage<V>
-
thenApply
<U> FutureCompletionStage<U> thenApply(Function<? super V,? extends U> fn)
- Specified by:
thenApplyin interfaceCompletionStage<V>
-
thenApplyAsync
<U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<V>
-
thenAccept
FutureCompletionStage<Void> thenAccept(Consumer<? super V> action)
- Specified by:
thenAcceptin interfaceCompletionStage<V>
-
thenAcceptAsync
FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<V>
-
thenRun
FutureCompletionStage<Void> thenRun(Runnable action)
- Specified by:
thenRunin interfaceCompletionStage<V>
-
thenRunAsync
FutureCompletionStage<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsyncin interfaceCompletionStage<V>
-
thenCombine
<U,V1> FutureCompletionStage<V1> thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombinein interfaceCompletionStage<V>
-
thenCombineAsync
<U,V1> FutureCompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<V>
-
thenAcceptBoth
<U> FutureCompletionStage<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothin interfaceCompletionStage<V>
-
thenAcceptBothAsync
<U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<V>
-
runAfterBoth
FutureCompletionStage<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothin interfaceCompletionStage<V>
-
runAfterBothAsync
FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<V>
-
applyToEither
<U> FutureCompletionStage<U> applyToEither(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherin interfaceCompletionStage<V>
-
applyToEitherAsync
<U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<V>
-
acceptEither
FutureCompletionStage<Void> acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherin interfaceCompletionStage<V>
-
acceptEitherAsync
FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<V>
-
runAfterEither
FutureCompletionStage<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherin interfaceCompletionStage<V>
-
runAfterEitherAsync
FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<V>
-
thenCompose
<U> FutureCompletionStage<U> thenCompose(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposein interfaceCompletionStage<V>
-
thenComposeAsync
<U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<V>
-
whenComplete
FutureCompletionStage<V> whenComplete(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompletein interfaceCompletionStage<V>
-
whenCompleteAsync
FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<V>
-
handle
<U> FutureCompletionStage<U> handle(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handlein interfaceCompletionStage<V>
-
handleAsync
<U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handleAsyncin interfaceCompletionStage<V>
-
thenApplyAsync
<U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<V>
-
thenAcceptAsync
FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action, Executor executor)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<V>
-
thenRunAsync
FutureCompletionStage<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsyncin interfaceCompletionStage<V>
-
thenCombineAsync
<U,V1> FutureCompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn, Executor executor)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<V>
-
thenAcceptBothAsync
<U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<V>
-
runAfterBothAsync
FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<V>
-
applyToEitherAsync
<U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn, Executor executor)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<V>
-
acceptEitherAsync
FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<V>
-
runAfterEitherAsync
FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<V>
-
thenComposeAsync
<U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<V>
-
exceptionally
FutureCompletionStage<V> exceptionally(Function<Throwable,? extends V> fn)
- Specified by:
exceptionallyin interfaceCompletionStage<V>
-
whenCompleteAsync
FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<V>
-
handleAsync
<U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsyncin interfaceCompletionStage<V>
-
toFutureCompletionStage
static <U> FutureCompletionStage<U> toFutureCompletionStage(CompletionStage<U> stage, EventExecutor executor)
Returns aFutureCompletionStagefor the givenCompletionStagethat is pinned to the givenEventExecutor.
-
isCancelled
boolean isCancelled()
Returntrueif this operation has been cancelled.- Returns:
trueif this operation has been cancelled, otherwisefalse.
-
isDone
boolean isDone()
Returntrueif this operation has been completed either successfully, unsuccessfully, or through cancellation.- Returns:
trueif this operation has completed, otherwisefalse.
-
-