Class FutureUtil

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.util.FutureUtil

public final class FutureUtil extends Object
Utility class for futures.
  • Method Details

    • logPossibleDeadlockTimeout

      public static void logPossibleDeadlockTimeout(com.google.common.flogger.LazyArg<?> context, int timeoutMs, boolean isMainThread)
      Logs a possible deadlock timeout.
      Parameters:
      context - The context in which the deadlock occurred.
      timeoutMs - The timeout in milliseconds. This is the time that the thread was waiting before considering it a deadlock.
      isMainThread - Whether the thread that timed out is the main thread.
    • getAllCompletableFutureResults

      public static <T> CompletableFuture<List<T>> getAllCompletableFutureResults(Collection<CompletableFuture<T>> futures)
    • getAllCompletableFutureResults

      @SafeVarargs public static <T> CompletableFuture<List<T>> getAllCompletableFutureResults(CompletableFuture<T>... futures)
      Maps a group of CompletableFutures to a single CompletableFuture with a list of results.

      The result will wait for each of the futures to complete and once all of them have completed gather the results and return the list.

      Each entry in the list maps to the result of a single future.

      Type Parameters:
      T - The type of data.
      Parameters:
      futures - The completable futures whose results to collect into a list.
      Returns:
      The list of results obtained from the CompletableFutures in the same order as provided. The list will have a size that matches the number of input futures.
    • getAllCompletableFutureResultsFlatMap

      public static <T> CompletableFuture<List<T>> getAllCompletableFutureResultsFlatMap(Collection<CompletableFuture<? extends Collection<T>>> futures)
    • getAllCompletableFutureResultsFlatMap

      @SafeVarargs public static <T> CompletableFuture<List<T>> getAllCompletableFutureResultsFlatMap(CompletableFuture<? extends Collection<T>>... futures)
      Maps a group of CompletableFutures that each have a list as result to a single CompletableFuture with a list.

      The result will wait for each of the futures to complete and once all of them have completed gather the results and return the list.

      The results of the futures are flatMapped into a single list.

      Type Parameters:
      T - The type of data in the lists.
      Parameters:
      futures - The completable futures whose results to flatMap into a list.
      Returns:
      The list of results obtained from the CompletableFutures.