Package convex.core.util
Class ThreadUtils
java.lang.Object
convex.core.util.ThreadUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <R> voidawaitAll(Collection<CompletableFuture<R>> futures) Awaits the result of all of a collection of futuresstatic <T> CompletableFuture<List<T>> completeAll(List<CompletableFuture<T>> futures) static <R,T> ArrayList <CompletableFuture<R>> futureMap(ExecutorService executor, Function<? super T, R> f, Collection<T> items) Executes functions on for each element of a collection, returning a list of futuresstatic ExecutorServiceGet the current virtual thread ExecutorService, intended for IO-bound blocking operationsstatic voidrunVirtual(Runnable task) Runs a (probably IO-bound) task in a virtual thread if available,
-
Constructor Details
-
ThreadUtils
public ThreadUtils()
-
-
Method Details
-
getVirtualExecutor
Get the current virtual thread ExecutorService, intended for IO-bound blocking operations- Returns:
- Executor service
-
futureMap
public static <R,T> ArrayList<CompletableFuture<R>> futureMap(ExecutorService executor, Function<? super T, R> f, Collection<T> items) Executes functions on for each element of a collection, returning a list of futures- Type Parameters:
R- Result type of functionT- Argument type- Parameters:
executor- ExecutorService with which to run functionsf- Function to runitems- Collection of items to run futures on- Returns:
- List of futures for each item
-
awaitAll
public static <R> void awaitAll(Collection<CompletableFuture<R>> futures) throws InterruptedException, ExecutionException Awaits the result of all of a collection of futures- Type Parameters:
R- Type of futures- Parameters:
futures- A collection of futures- Throws:
InterruptedExceptionExecutionException
-
completeAll
-
runVirtual
Runs a (probably IO-bound) task in a virtual thread if available,- Parameters:
task- Task to run
-