Class CompletableFutureUtil

java.lang.Object
com.hypixel.hytale.common.util.CompletableFutureUtil

public class CompletableFutureUtil extends Object
  • Field Details

  • Constructor Details

    • CompletableFutureUtil

      public CompletableFutureUtil()
  • Method Details

    • whenComplete

      @Nonnull public static <T> CompletableFuture<T> whenComplete(@Nonnull CompletableFuture<T> future, @Nonnull CompletableFuture<T> callee)
    • isCanceled

      public static boolean isCanceled(Throwable throwable)
    • _catch

      @Nonnull public static <T> CompletableFuture<T> _catch(@Nonnull CompletableFuture<T> future)
    • completionCanceled

      @Nonnull public static <T> CompletableFuture<T> completionCanceled()
      Returns a new CompletableFuture that has already been canceled. Useful for ending a chain of prebuilt futures.
      Type Parameters:
      T - The type of the CompletableFuture.
      Returns:
      A CompletableFuture that has been canceled.
    • joinWithProgress

      public static void joinWithProgress(@Nonnull List<CompletableFuture<?>> list, @Nonnull CompletableFutureUtil.ProgressConsumer callback, int millisSleep, int millisProgress) throws InterruptedException
      Accepts a list of CompletableFuture and waits for them all to complete, giving progress reports every millisProgress milliseconds, with the progress reports going to the ProgressConsumer passed as the argument to this method. The current thread will be blocked until all CompletableFutures have completed, with them being checked for completion every millisTest milliseconds.
      Parameters:
      list - The list of CompletableFutures to wait on
      callback - The target of the progress, which will be given doubles ranging from 0 to 1 as well as the current number of operations completed and the final number of operations. See CompletableFutureUtil.ProgressConsumer.accept(double, int, int) for more information.
      millisSleep - The number of milliseconds the thread should sleep for between checking
      millisProgress - The number of milliseconds between progress reports
      Throws:
      InterruptedException - If the thread is interrupted