Package org.eclipse.jetty.util
Class CompletableTask<T>
java.lang.Object
java.util.concurrent.CompletableFuture<T>
org.eclipse.jetty.util.CompletableTask<T>
- Type Parameters:
T
- the type of the result of the task
- All Implemented Interfaces:
Runnable
,CompletionStage<T>
,Future<T>
A CompletableFuture
that implements Runnable
to perform
a one-shot task that eventually completes this CompletableFuture
.
Subclasses override Runnable.run()
to implement the task.
Users of this class start the task execution via start()
.
Typical usage:
CompletableTask<T> task = new CompletableTask<>()
{
@Override
public void run()
{
try
{
// Perform some task.
T result = performTask();
// Eventually complete this CompletableFuture.
complete(result);
}
catch (Throwable x)
{
completeExceptionally(x);
}
}
}
// Start the task and then process the
// result of the task when it is complete.
task.start()
.whenComplete((result, failure) ->
{
if (failure == null)
{
// The task completed successfully.
}
else
{
// The task failed.
}
});
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstart()
Starts the task by callingRunnable.run()
and returns thisCompletableTask
.Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
-
Constructor Details
-
CompletableTask
public CompletableTask()
-
-
Method Details
-
start
Starts the task by calling
Runnable.run()
and returns thisCompletableTask
.- Returns:
- this
CompletableTask
-