Class ListenableTask<V>

java.lang.Object
java.util.concurrent.CompletableFuture<V>
eu.cloudnetservice.utils.base.concurrent.ListenableTask<V>
Type Parameters:
V - the generic type of the task.
All Implemented Interfaces:
CompletionStage<V>, Future<V>

public class ListenableTask<V> extends CompletableFuture<V>
The listenable task is a task that is allowed to be executed over and over again. The task wraps a callable and calls it on each run of the task. Once the result of the task is completed using task.run(true) the task cannot run anymore, and it switches into the done state.
Since:
4.0
  • Field Details

  • Constructor Details

    • ListenableTask

      public ListenableTask(@NonNull @NonNull Callable<V> callable)
      Constructs a new listenable task with the given callable
      Parameters:
      callable - the callable to call on each run.
      Throws:
      NullPointerException - if the given callable is null.
  • Method Details

    • run

      public void run(boolean setResult)
      Runs the callable provided to this listenable task. This task supports running it over and over again until the result it set and the task completed with that result.
      Parameters:
      setResult - whether the result of the callable should be set as result of this task.