Class Futures

java.lang.Object
com.github.mizool.core.concurrent.Futures

public final class Futures extends Object
  • Method Details

    • get

      public static <V> V get(@NonNull @NonNull Future<V> future)
      Waits if necessary for the computation to complete, and then retrieves its result.
      Returns:
      the computed result
      Throws:
      com.google.common.util.concurrent.UncheckedExecutionException - if the computation threw an exception
      CancellationException - if the computation was cancelled
      UncheckedInterruptedException - if the thread was interrupted while waiting. Note: as required, the thread will be re-interrupted before throwing the exception.
      NullPointerException - if future is null
    • get

      public static <V> V get(@NonNull @NonNull Future<V> future, @NonNull @NonNull Duration duration)
      Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
      Returns:
      the computed result
      Throws:
      com.google.common.util.concurrent.UncheckedTimeoutException - if the computation timed out
      com.google.common.util.concurrent.UncheckedExecutionException - if the computation threw an exception
      CancellationException - if the computation was cancelled
      UncheckedInterruptedException - if the thread was interrupted while waiting. Note: as required, the thread will be re-interrupted before throwing the exception.
      NullPointerException - if future or duration is null
    • toVoidResult

      public static com.google.common.util.concurrent.ListenableFuture<Void> toVoidResult(@NonNull @NonNull com.google.common.util.concurrent.ListenableFuture<?> future)
      Transforms any ListenableFuture into a ListenableFuture without result. Exceptions that are thrown by the original future are handled transparently.

      The returned future does not contain a reference to the original future. That allows to reduce the overall memory footprint when working with multiple futures at once without caring for the results.
      Parameters:
      future - the future to wrap
      Returns:
      a void future
      Throws:
      NullPointerException - if future is null
    • toVoidResult

      public static CompletableFuture<Void> toVoidResult(@NonNull @NonNull CompletableFuture<?> future)
      Transforms any CompletableFuture into a CompletableFuture without result. Exceptions that are thrown by the original future are handled transparently.

      The returned future does not contain a reference to the original future. That allows to reduce the overall memory footprint when working with multiple futures at once without caring for the results.
      Parameters:
      future - the future to wrap
      Returns:
      a void future
      Throws:
      NullPointerException - if future is null