Class CompetitiveFuture<T>

java.lang.Object
java.util.concurrent.CompletableFuture<T>
space.arim.omnibus.util.concurrent.CompetitiveFuture<T>
Type Parameters:
T - the result type of the future
All Implemented Interfaces:
CompletionStage<T>, Future<T>

public class CompetitiveFuture<T> extends CompletableFuture<T>
A CompletableFuture with a specified default executor, which is used as the default executor in all future async operations.
Author:
A248
  • Constructor Details

    • CompetitiveFuture

      public CompetitiveFuture(Executor defaultExecutor)
      Creates an incomplete future from the default executor to use
      Parameters:
      defaultExecutor - the default executor for asynchronous operations
      Throws:
      NullPointerException - if defaultExecutor is null
  • Method Details

    • newIncompleteFuture

      public <U> CompletableFuture<U> newIncompleteFuture()
      Overrides:
      newIncompleteFuture in class CompletableFuture<T>
    • defaultExecutor

      public Executor defaultExecutor()
      Overrides:
      defaultExecutor in class CompletableFuture<T>
    • runAsync

      public static CompetitiveFuture<Void> runAsync(Runnable command, Executor defaultExecutor)
      Runs an action asynchronously. See CompletableFuture.runAsync(Runnable).
      If the specified default executor is null, the common ForkJoinPool is used.
      Parameters:
      command - what to do
      defaultExecutor - the default executor used for async methods not specifying an executor
      Returns:
      a competitive future running the specified command
    • supplyAsync

      public static <T> CompetitiveFuture<T> supplyAsync(Supplier<T> supplier, Executor defaultExecutor)
      Supplies a value asynchronously. See CompletableFuture.supplyAsync(Supplier).
      If the specified default executor is null, the common ForkJoinPool is used.
      Type Parameters:
      T - the type of the future
      Parameters:
      supplier - the supplier from which to get the value
      defaultExecutor - the default executor used for async methods not specifying an executor
      Returns:
      a competitive future supplying a value via the specified supplier
    • completedFuture

      public static <T> CompetitiveFuture<T> completedFuture(T value, Executor defaultExecutor)
      Creates a precompleted future with the specified value.
      Type Parameters:
      T - the type of the future
      Parameters:
      value - the value with which to complete it
      defaultExecutor - the default executor used for async methods not specifying an executor
      Returns:
      a competitive future completed with the specified value
    • failedFuture

      public static <T> CompetitiveFuture<T> failedFuture(Throwable ex, Executor defaultExecutor)
      Creates a future completed exceptionally with the specified exception.
      Type Parameters:
      T - the type of the future
      Parameters:
      ex - the exception with which to complete it
      defaultExecutor - the default executor, used for async methods not specifying an executor
      Returns:
      a competitive future completed exceptionally with the specified exception