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>

public abstract class CompletableTask<T> extends CompletableFuture<T> implements Runnable

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.
         }
     });