Class CompletableFutures

java.lang.Object
ru.progrm_jarvis.javacommons.util.concurrent.CompletableFutures

public final class CompletableFutures extends Object
Utilities related to completable futures.
  • Method Details

    • exceptionallyCompletedFuture

      @NotNull public static <@Any T> @NotNull CompletableFuture<T> exceptionallyCompletedFuture(@NonNull @NonNull Throwable throwable)
      Creates a completable future which instantly completes exceptionally with the provided throwable.
      Type Parameters:
      T - the result type of the future
      Parameters:
      throwable - throwable with which the future completes exceptionally
      Returns:
      the exceptionally completed future
      Throws:
      NullPointerException - if throwable is null
    • bothOf

      @NotNull public static <F, S> @NotNull CompletableFuture<@NotNull Pair<F,S>> bothOf(@NonNull @NonNull CompletableFuture<F> first, @NonNull @NonNull CompletableFuture<S> second)
      Returns the completable future whose result is a pair of the provided future's results if both of them complete. The future completes exceptionally if any of the given futures completes exceptionally.
      Type Parameters:
      F - the result type of the first future
      S - the result type of the second future
      Parameters:
      first - first future
      second - second future
      Returns:
      a new completable future that is completed when both of the given futures complete
      Throws:
      NullPointerException - if first is null
      NullPointerException - if second is null
      See Also:
    • eitherOf

      @NotNull public static <F, S> @NotNull CompletableFuture<@NotNull Result<F,S>> eitherOf(@NonNull @NonNull CompletableFuture<F> successFuture, @NonNull @NonNull CompletableFuture<S> errorFuture)
      Returns the completable future whose result is the result of either the first or the second future wrapped in either a successful result or an error result respectively. The future completes exceptionally if the first completing future completes exceptionally.
      Type Parameters:
      F - the result type of the first future
      S - the result type of the second future
      Parameters:
      successFuture - first futures
      errorFuture - second futures
      Returns:
      a new completable future that is completed when either of the given futures completes
      Throws:
      NullPointerException - if successFuture is null
      NullPointerException - if errorFuture is null
      See Also: