Package graphql.execution
Class Async
- java.lang.Object
-
- graphql.execution.Async
-
public class Async extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Async.CombinedBuilder<T>
A builder of materialized objects orCompletableFuture
s than can present a promise to the list of them
-
Constructor Summary
Constructors Constructor Description Async()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,U>
java.util.concurrent.CompletableFuture<java.util.List<U>>each(java.util.Collection<T> list, java.util.function.Function<T,java.lang.Object> cfOrMaterialisedValueFactory)
static <T> java.lang.Object
eachPolymorphic(java.util.Collection<T> list, java.util.function.Function<T,java.lang.Object> cfOrMaterialisedValueFactory)
This will run the value factory for each of the values in the provided list.static <T,U>
java.util.concurrent.CompletableFuture<java.util.List<U>>eachSequentially(java.lang.Iterable<T> list, java.util.function.BiFunction<T,java.util.List<U>,java.lang.Object> cfOrMaterialisedValueFactory)
static <T> java.util.concurrent.CompletableFuture<T>
exceptionallyCompletedFuture(java.lang.Throwable exception)
static <T> Async.CombinedBuilder<T>
ofExpectedSize(int expectedSize)
Combines zero or more CFs into one.static <T> @NotNull java.util.concurrent.CompletableFuture<T>
orNullCompletedFuture(@Nullable java.util.concurrent.CompletableFuture<T> completableFuture)
If the passed in CompletableFuture is null, then it creates a CompletableFuture that resolves to nullstatic <T> java.util.concurrent.CompletableFuture<T>
toCompletableFuture(java.lang.Object t)
Turns an object T into a CompletableFuture if it's not alreadystatic java.lang.Object
toCompletableFutureOrMaterializedObject(java.lang.Object object)
Turns a CompletionStage into a CompletableFuture if it's not already, otherwise leaves it alone as a materialized object.static <T> java.util.concurrent.CompletableFuture<T>
tryCatch(java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>> supplier)
-
-
-
Method Detail
-
ofExpectedSize
public static <T> Async.CombinedBuilder<T> ofExpectedSize(int expectedSize)
Combines zero or more CFs into one. It is a wrapper aroundCompletableFuture.allOf
.- Type Parameters:
T
- for two- Parameters:
expectedSize
- how many we expect- Returns:
- a combined builder of CFs
-
each
public static <T,U> java.util.concurrent.CompletableFuture<java.util.List<U>> each(java.util.Collection<T> list, java.util.function.Function<T,java.lang.Object> cfOrMaterialisedValueFactory)
-
eachPolymorphic
public static <T> java.lang.Object eachPolymorphic(java.util.Collection<T> list, java.util.function.Function<T,java.lang.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 aCompletableFuture
result object that joins on all values otherwise if none of the values are aCompletableFuture
then it will return a materialized list.- Type Parameters:
T
- for two- Parameters:
list
- the list to work overcfOrMaterialisedValueFactory
- 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> java.util.concurrent.CompletableFuture<java.util.List<U>> eachSequentially(java.lang.Iterable<T> list, java.util.function.BiFunction<T,java.util.List<U>,java.lang.Object> cfOrMaterialisedValueFactory)
-
toCompletableFuture
public static <T> java.util.concurrent.CompletableFuture<T> toCompletableFuture(java.lang.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 java.lang.Object toCompletableFutureOrMaterializedObject(java.lang.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> java.util.concurrent.CompletableFuture<T> tryCatch(java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>> supplier)
-
exceptionallyCompletedFuture
public static <T> java.util.concurrent.CompletableFuture<T> exceptionallyCompletedFuture(java.lang.Throwable exception)
-
orNullCompletedFuture
@NotNull public static <T> @NotNull java.util.concurrent.CompletableFuture<T> orNullCompletedFuture(@Nullable @Nullable java.util.concurrent.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
-
-