Class Futures

java.lang.Object
io.atomix.utils.concurrent.Futures

public final class Futures extends Object
Utilities for creating completed and exceptional futures.
Author:
Jordan Halterman
  • Constructor Details

    • Futures

      public Futures()
  • Method Details

    • get

      public static <T> T get(Future<T> future)
      Gets a future result with a default timeout.
      Type Parameters:
      T - the future result type
      Parameters:
      future - the future to block
      Returns:
      the future result
      Throws:
      RuntimeException - if a future exception occurs
    • get

      public static <T> T get(Future<T> future, long timeout, TimeUnit timeUnit)
      Gets a future result with a default timeout.
      Type Parameters:
      T - the future result type
      Parameters:
      future - the future to block
      timeout - the future timeout
      timeUnit - the future timeout time unit
      Returns:
      the future result
      Throws:
      RuntimeException - if a future exception occurs
    • completedFuture

      public static <T> CompletableFuture<T> completedFuture(T result)
      Creates a future that is synchronously completed.
      Parameters:
      result - The future result.
      Returns:
      The completed future.
    • exceptionalFuture

      public static <T> CompletableFuture<T> exceptionalFuture(Throwable t)
      Creates a future that is synchronously completed exceptionally.
      Parameters:
      t - The future exception.
      Returns:
      The exceptionally completed future.
    • allOf

      public static <T> CompletableFuture<Stream<T>> allOf(Stream<CompletableFuture<T>> futures)
      Returns a new CompletableFuture completed with a list of computed values when all of the given CompletableFuture complete.
      Type Parameters:
      T - value type of CompletableFuture
      Parameters:
      futures - the CompletableFutures
      Returns:
      a new CompletableFuture that is completed when all of the given CompletableFutures complete
    • allOf

      public static <T> CompletableFuture<List<T>> allOf(List<CompletableFuture<T>> futures)
      Returns a new CompletableFuture completed with a list of computed values when all of the given CompletableFuture complete.
      Type Parameters:
      T - value type of CompletableFuture
      Parameters:
      futures - the CompletableFutures
      Returns:
      a new CompletableFuture that is completed when all of the given CompletableFutures complete
    • allOf

      public static <T> CompletableFuture<T> allOf(List<CompletableFuture<T>> futures, BinaryOperator<T> reducer, T emptyValue)
      Returns a new CompletableFuture completed by reducing a list of computed values when all of the given CompletableFuture complete.
      Type Parameters:
      T - value type of CompletableFuture
      Parameters:
      futures - the CompletableFutures
      reducer - reducer for computing the result
      emptyValue - zero value to be returned if the input future list is empty
      Returns:
      a new CompletableFuture that is completed when all of the given CompletableFutures complete