A CompletableFuture that implements Runnable to perform
a one-shot task that eventually completes this CompletableFuture.
Subclasses override 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.
}
});
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public CompletableTask | Returns: thisCompletableTaskStarts the task by calling |
| CompletableTask | back to summary |
|---|---|
| public CompletableTask() | |
| start | back to summary |
|---|---|
| public CompletableTask Starts the task by calling
| |