Class Async

java.lang.Object
graphql.execution.Async

public class Async extends Object
  • Constructor Details

    • Async

      public Async()
  • Method Details

    • ofExpectedSize

      public static <T> Async.CombinedBuilder<T> ofExpectedSize(int expectedSize)
      Combines zero or more CFs into one. It is a wrapper around CompletableFuture.allOf.
      Type Parameters:
      T - for two
      Parameters:
      expectedSize - how many we expect
      Returns:
      a combined builder of CFs
    • each

      public static <T, U> CompletableFuture<List<U>> each(Collection<T> list, Function<T,Object> cfOrMaterialisedValueFactory)
    • eachPolymorphic

      public static <T> Object eachPolymorphic(Collection<T> list, Function<T,Object> cfOrMaterialisedValueFactory)
      This will run the value factory for each of the values in the provided list.

      If any of the values provided is a CompletableFuture it will return a CompletableFuture result object that joins on all values otherwise if none of the values are a CompletableFuture then it will return a materialized list.

      Type Parameters:
      T - for two
      Parameters:
      list - the list to work over
      cfOrMaterialisedValueFactory - the value factory to call for each iterm in the list
      Returns:
      a CompletableFuture to the list of resolved values or the list of values in a materialized fashion
    • eachSequentially

      public static <T, U> CompletableFuture<List<U>> eachSequentially(Iterable<T> list, BiFunction<T,List<U>,Object> cfOrMaterialisedValueFactory)
    • toCompletableFuture

      public static <T> CompletableFuture<T> toCompletableFuture(Object t)
      Turns an object T into a CompletableFuture if it's not already
      Type Parameters:
      T - for two
      Parameters:
      t - - the object to check
      Returns:
      a CompletableFuture
    • toCompletableFutureOrMaterializedObject

      public static Object toCompletableFutureOrMaterializedObject(Object object)
      Turns a CompletionStage into a CompletableFuture if it's not already, otherwise leaves it alone as a materialized object.
      Parameters:
      object - - the object to check
      Returns:
      a CompletableFuture from a CompletionStage or the materialized object itself
    • tryCatch

      public static <T> CompletableFuture<T> tryCatch(Supplier<CompletableFuture<T>> supplier)
    • exceptionallyCompletedFuture

      public static <T> CompletableFuture<T> exceptionallyCompletedFuture(Throwable exception)
    • orNullCompletedFuture

      public static <T> @NonNull CompletableFuture<T> orNullCompletedFuture(@Nullable CompletableFuture<T> completableFuture)
      If the passed in CompletableFuture is null, then it creates a CompletableFuture that resolves to null
      Type Parameters:
      T - for two
      Parameters:
      completableFuture - the CF to use
      Returns:
      the completableFuture if it's not null or one that always resoles to null