Package io.hekate.util.async
Class AsyncUtils
- java.lang.Object
-
- io.hekate.util.async.AsyncUtils
-
public final class AsyncUtils extends Object
Set of utility methods for asynchronous tasks processing.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CompletableFuture<Void>
allOf(Collection<CompletableFuture<?>> all)
Version ofCompletableFuture.allOf(CompletableFuture[])
that works with a collection instead of an array.static Future<?>
cancelledFuture()
Returns a cancelledFuture
.static Executor
fallbackExecutor()
Fallback executor.static <T> T
getUninterruptedly(Future<T> future)
Uninterruptedly waits for the specifiedFuture
to complete, and then returns its result.static Waiting
shutdown(ExecutorService executor)
-
-
-
Method Detail
-
fallbackExecutor
public static Executor fallbackExecutor()
Fallback executor.Returns a single-threaded executor instance that can be used run tasks that couldn't be executed on their own executors for some reasons. This executor should not be used for execution of a regular flow tasks.
- Returns:
- Fallback executor.
-
shutdown
public static Waiting shutdown(ExecutorService executor)
- Parameters:
executor
- Executor service to shut down.- Returns:
- Waiting for
termination
.
-
getUninterruptedly
public static <T> T getUninterruptedly(Future<T> future) throws ExecutionException
Uninterruptedly waits for the specifiedFuture
to complete, and then returns its result.- Type Parameters:
T
- Result type.- Parameters:
future
- Future.- Returns:
- Result of the
Future.get()
method. - Throws:
ExecutionException
- If thrown by theFuture.get()
method.
-
allOf
public static CompletableFuture<Void> allOf(Collection<CompletableFuture<?>> all)
Version ofCompletableFuture.allOf(CompletableFuture[])
that works with a collection instead of an array.- Parameters:
all
- Collection of future objects.- Returns:
- Future that is completed when all of the given CompletableFutures complete.
- See Also:
CompletableFuture.allOf(CompletableFuture[])
-
-