T - a type of the successfully executed task resultpublic class CompletableTask<T> extends PromiseAdapter<T>
Promise interface for long-running blocking tasks| Modifier and Type | Field and Description |
|---|---|
protected RunnableFuture<T> |
task |
SAME_THREAD_EXECUTOR| Modifier | Constructor and Description |
|---|---|
protected |
CompletableTask(Executor executor,
Callable<T> callable)
Creates a CompletableTask; for internal use only
|
| Modifier and Type | Method and Description |
|---|---|
Promise<Void> |
acceptEitherAsync(CompletionStage<? extends T> other,
Consumer<? super T> action,
Executor executor) |
<U> Promise<U> |
applyToEitherAsync(CompletionStage<? extends T> other,
Function<? super T,U> fn,
Executor executor) |
static Promise<Void> |
asyncOn(Executor executor)
Returns a resolved no-value
Promise that is "bound" to the specified executor. |
static Promise<Void> |
asyncOn(Executor executor,
boolean enforceDefaultAsync)
Returns a resolved no-value
Promise that is "bound" to the specified executor. |
boolean |
cancel(boolean mayInterruptIfRunning) |
static <T> Promise<T> |
completed(T value,
Executor defaultExecutor)
Returns a resolved
Promise with specified value; the promise is "bound" to the specified executor. |
protected static <V,R> Function<V,R> |
consumerAsFunction(Consumer<? super V> action) |
protected <U> net.tascalate.concurrent.AbstractCompletableTask<U> |
createCompletionStage(Executor executor)
Creates a nested sub-task for a composition method
|
static Promise<Duration> |
delay(Duration duration,
Executor executor) |
static Promise<Duration> |
delay(long timeout,
TimeUnit unit,
Executor executor) |
protected <R,U> Promise<U> |
doApplyToEitherAsync(CompletionStage<? extends R> first,
CompletionStage<? extends R> second,
Function<? super R,U> fn,
Executor executor)
This method exists just to reconcile generics when called from
runAfterEitherAsync(java.util.concurrent.CompletionStage<?>, java.lang.Runnable, java.util.concurrent.Executor) which has unexpected type of parameter
"other". |
Promise<T> |
exceptionallyAsync(Function<Throwable,? extends T> fn,
Executor executor) |
Promise<T> |
exceptionallyComposeAsync(Function<Throwable,? extends CompletionStage<T>> fn,
Executor executor) |
protected static <U> Function<Throwable,U> |
forwardException() |
protected static <U> U |
forwardException(Throwable e) |
T |
get() |
T |
get(long timeout,
TimeUnit unit) |
<U> Promise<U> |
handleAsync(BiFunction<? super T,Throwable,? extends U> fn,
Executor executor) |
boolean |
isCancelled() |
boolean |
isCompletedExceptionally() |
boolean |
isDone() |
Promise<Void> |
runAfterBothAsync(CompletionStage<?> other,
Runnable action,
Executor executor) |
Promise<Void> |
runAfterEitherAsync(CompletionStage<?> other,
Runnable action,
Executor executor) |
static Promise<Void> |
runAsync(Runnable runnable,
Executor executor)
Returns a new
Promise that is asynchronously resolved by a task running in the given executor
after it runs the given action. |
protected void |
runTask() |
static <U> Promise<U> |
submit(Callable<U> call,
Executor executor)
|
static <U> Promise<U> |
supplyAsync(Supplier<U> supplier,
Executor executor)
|
Promise<Void> |
thenAcceptAsync(Consumer<? super T> action,
Executor executor) |
<U> Promise<Void> |
thenAcceptBothAsync(CompletionStage<? extends U> other,
BiConsumer<? super T,? super U> action,
Executor executor) |
<U> Promise<U> |
thenApplyAsync(Function<? super T,? extends U> fn,
Executor executor) |
<U,V> Promise<V> |
thenCombineAsync(CompletionStage<? extends U> other,
BiFunction<? super T,? super U,? extends V> fn,
Executor executor) |
<U> Promise<U> |
thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn,
Executor executor) |
Promise<T> |
thenFilterAsync(Predicate<? super T> predicate,
Function<? super T,Throwable> errorSupplier,
Executor executor) |
Promise<Void> |
thenRunAsync(Runnable action,
Executor executor) |
CompletableFuture<T> |
toCompletableFuture() |
String |
toString() |
static <T> Promise<T> |
waitFor(CompletionStage<T> stage,
Executor executor) |
static <T> Promise<T> |
waitFor(CompletionStage<T> stage,
Executor executor,
boolean dependentStage) |
Promise<T> |
whenCompleteAsync(BiConsumer<? super T,? super Throwable> action,
Executor executor) |
acceptEither, acceptEitherAsync, applyToEither, applyToEitherAsync, exceptionally, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, getDefaultExecutor, handle, handleAsync, runAfterBoth, runAfterBothAsync, runAfterEither, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenApply, thenApplyAsync, thenCombine, thenCombineAsync, thenCompose, thenComposeAsync, thenFilter, thenFilter, thenFilterAsync, thenFilterAsync, thenRun, thenRunAsync, whenComplete, whenCompleteAsyncclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitacceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, as, defaultAsyncOn, delay, delay, delay, delay, dependent, dependent, exceptionally, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, getNow, getNow, handle, handleAsync, join, onCancel, onTimeout, onTimeout, onTimeout, onTimeout, onTimeout, onTimeout, onTimeout, onTimeout, orTimeout, orTimeout, orTimeout, orTimeout, raw, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenFilter, thenFilter, thenFilterAsync, thenFilterAsync, thenFilterAsync, thenFilterAsync, thenRun, thenRunAsync, thenRunAsync, unwrap, whenComplete, whenCompleteAsyncprotected final RunnableFuture<T> task
public static <T> Promise<T> completed(T value, Executor defaultExecutor)
Promise with specified value; the promise is "bound" to the specified executor.
I.e. any function passed to composition methods of Promise (like thenApplyAsync
/ thenAcceptAsync / whenCompleteAsync etc.) will be executed using this executor
unless executor is overridden via explicit composition method parameter. Moreover, any nested
composition calls will use same executor, if it’s not redefined via explicit composition method parameter:
CompletableTask
.complete("Hello!", myExecutor)
.thenApplyAsync(myMapper)
.thenApplyAsync(myTransformer)
.thenAcceptAsync(myConsumer)
.thenRunAsync(myAction)
All of myMapper, myTransformer, myConsumer, myActtion
will be executed using myExecutorT - a type of the successfully executed task resultvalue - a task resultdefaultExecutor - a default Executor to run functions passed to async composition methods
(like thenApplyAsync / thenAcceptAsync / whenCompleteAsync etc.)Promise with a value passed; the promise is bound to the specified executorpublic static Promise<Void> asyncOn(Executor executor)
Promise that is "bound" to the specified executor.
I.e. any function passed to composition methods of Promise (like thenApplyAsync
/ thenAcceptAsync / whenCompleteAsync etc.) will be executed using this executor
unless executor is overridden via explicit composition method parameter. Moreover, any nested
composition calls will use same executor, if it’s not redefined via explicit composition method parameter:
CompletableTask .asyncOn(myExecutor) .thenApplyAsync(myValueGenerator) .thenAcceptAsync(myConsumer) .thenRunAsync(myAction)All of
myValueGenerator, myConsumer, myActtion will be executed
using myExecutorpublic static Promise<Void> asyncOn(Executor executor, boolean enforceDefaultAsync)
Promise that is "bound" to the specified executor.
I.e. any function passed to composition methods of Promise (like thenApplyAsync
/ thenAcceptAsync / whenCompleteAsync etc.) will be executed using this executor
unless executor is overridden via explicit composition method parameter. Moreover, any nested
composition calls will use same executor, if it’s not redefined via explicit composition method parameter:
CompletableTask .asyncOn(myExecutor) .thenApplyAsync(myValueGenerator) .thenAcceptAsync(myConsumer) .thenRunAsync(myAction)
All of myValueGenerator, myConsumer, myActtion will be executed
using myExecutor.
Moreover, if enforceDefaultAsync is true, then default executor will be propagated to
dependent promises even if corresponding transition was executed on another executor (via composition methods
with explicit executor argument).
executor - a default Executor to run functions passed to async composition methods
(like thenApplyAsync / thenAcceptAsync / whenCompleteAsync etc.)enforceDefaultAsync - if true then default executor will be propagated to dependent promises
even if corresponding transition was executed on another executorPromise bound to the specified executorpublic static Promise<Void> runAsync(Runnable runnable, Executor executor)
Promise that is asynchronously resolved by a task running in the given executor
after it runs the given action.public static <T> Promise<T> waitFor(CompletionStage<T> stage, Executor executor)
public static <T> Promise<T> waitFor(CompletionStage<T> stage, Executor executor, boolean dependentStage)
protected void runTask()
protected <U> net.tascalate.concurrent.AbstractCompletableTask<U> createCompletionStage(Executor executor)
executor - a default executor for async composition methods of nested sub-taskCompletableSubTask bound to the specified executorpublic boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled in interface Future<T>public T get()
throws InterruptedException,
ExecutionException
get in interface Future<T>InterruptedExceptionExecutionExceptionpublic T get(long timeout,
TimeUnit unit)
throws InterruptedException,
ExecutionException,
TimeoutException
get in interface Future<T>InterruptedExceptionExecutionExceptionTimeoutExceptionpublic boolean isCompletedExceptionally()
isCompletedExceptionally in interface Promise<T>public <U> Promise<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
thenApplyAsync in interface CompletionStage<T>thenApplyAsync in interface Promise<T>public Promise<T> exceptionallyAsync(Function<Throwable,? extends T> fn, Executor executor)
exceptionallyAsync in interface Promise<T>public <U> Promise<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn, Executor executor)
handleAsync in interface CompletionStage<T>handleAsync in interface Promise<T>public <U> Promise<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)
thenComposeAsync in interface CompletionStage<T>thenComposeAsync in interface Promise<T>public Promise<T> exceptionallyComposeAsync(Function<Throwable,? extends CompletionStage<T>> fn, Executor executor)
exceptionallyComposeAsync in interface Promise<T>public Promise<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action, Executor executor)
whenCompleteAsync in interface CompletionStage<T>whenCompleteAsync in interface Promise<T>public CompletableFuture<T> toCompletableFuture()
toCompletableFuture in interface CompletionStage<T>protected <R,U> Promise<U> doApplyToEitherAsync(CompletionStage<? extends R> first, CompletionStage<? extends R> second, Function<? super R,U> fn, Executor executor)
runAfterEitherAsync(java.util.concurrent.CompletionStage<?>, java.lang.Runnable, java.util.concurrent.Executor) which has unexpected type of parameter
"other". The alternative is to ignore compiler warning.public Promise<T> thenFilterAsync(Predicate<? super T> predicate, Function<? super T,Throwable> errorSupplier, Executor executor)
public <U,V> Promise<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor)
public <U> Promise<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)
public Promise<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
public <U> Promise<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)
public Promise<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)
public Promise<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
protected static <U> U forwardException(Throwable e)
Copyright © 2021. All rights reserved.