Class CompletableFuture
-
- All Implemented Interfaces:
-
java.util.concurrent.Future
public class CompletableFuture<T> implements Future<V>
A stripped-down, Android-21-compatible version of java.util.concurrent.CompletableFuture.
-
-
Constructor Summary
Constructors Constructor Description CompletableFuture()
-
Method Summary
Modifier and Type Method Description static <U> CompletableFuture<U>completedFuture(U value)CompletableFuture<T>makeCancelable(TokioAsyncContext context)booleancancel(boolean mayInterruptIfRunning)synchronized booleanisCancelled()synchronized booleanisDone()booleancomplete(T result)booleancompleteExceptionally(Throwable throwable)synchronized Tget()synchronized Tget(long timeout, TimeUnit unit)<U> CompletableFuture<U>thenApply(Function<in T, out U> fn)Returns a future that will complete with the applied function applied to this future's completion value. <U> CompletableFuture<U>thenCompose(Function<in T, out CompletableFuture<U>> fn)Returns a future that will complete with the completion result of the future produced by applying a function to this future's completion value. CompletableFuture<T>whenComplete(BiConsumer<in T, Throwable> fn)Returns a future of the same type that will execute an action when the original future completes, successfully or not. <U> CompletableFuture<U>handle(BiFunction<in T, Throwable, out U> fn)Returns a future that, when this future completes (either normally or exceptionally), is completed with the result of invoking the given function. -
-
Method Detail
-
completedFuture
static <U> CompletableFuture<U> completedFuture(U value)
-
makeCancelable
CompletableFuture<T> makeCancelable(TokioAsyncContext context)
-
cancel
boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
synchronized boolean isCancelled()
-
isDone
synchronized boolean isDone()
-
complete
@CalledFromNative() boolean complete(T result)
-
completeExceptionally
@CalledFromNative() boolean completeExceptionally(Throwable throwable)
-
thenApply
<U> CompletableFuture<U> thenApply(Function<in T, out U> fn)
Returns a future that will complete with the applied function applied to this future's completion value.
If this future completes exceptionally, the exception will be propagated to the returned future. If this future completes normally but the applied function throws, the returned future will complete exceptionally with the thrown exception.
Note: Unlike the standard CompletableFuture implementation, cancellation propagates both downstream and upstream. If this future or the returned future is cancelled, all futures in the chain will be cancelled.
-
thenCompose
<U> CompletableFuture<U> thenCompose(Function<in T, out CompletableFuture<U>> fn)
Returns a future that will complete with the completion result of the future produced by applying a function to this future's completion value.
If this future completes exceptionally, the exception will be propagated to the returned future. If this future completes normally but the applied function throws, the returned future will complete exceptionally with the thrown exception. If the future produced by function application completes exceptionally, its error value will be propagated to the returned future.
Note: Unlike the standard CompletableFuture implementation, cancellation propagates both downstream and upstream. If this future or the returned future is cancelled, all futures in the chain will be cancelled.
-
whenComplete
CompletableFuture<T> whenComplete(BiConsumer<in T, Throwable> fn)
Returns a future of the same type that will execute an action when the original future completes, successfully or not.
The action will be invoked with (value, null) for successful completion of the source future, and (null, throwable) otherwise. If the source future completes exceptionally, the exception will be propagated to the returned future after executing the provided action. Any exceptions thrown by action itself are ignored in this case. If the source future succeeds but provided action throws an exception, this exception will be used to complete the resulting future exceptionally.
Note: Unlike the standard CompletableFuture implementation, cancellation propagates both downstream and upstream. If this future or the returned future is cancelled, all futures in the chain will be cancelled.
-
handle
<U> CompletableFuture<U> handle(BiFunction<in T, Throwable, out U> fn)
Returns a future that, when this future completes (either normally or exceptionally), is completed with the result of invoking the given function.
The function receives this future's value (or
nullif the future completed exceptionally) and the throwable that caused the failure (ornullon success). Whatever the function returns becomes the completion value of the returned future.If the function itself throws, the returned future completes exceptionally with that thrown exception.
Note: Unlike the standard CompletableFuture implementation, cancellation propagates both downstream and upstream. If this future or the returned future is cancelled, all futures in the chain will be cancelled.
-
-
-
-