Interface Async<R>
- Type Parameters:
R- The type of the result of the asynchronous operation
- All Known Subinterfaces:
ApplyFunction<T,,R> AsyncApplyFunction<T,,R> AsyncBiFunction<T,,P, R> AsyncCatchFunction<R,,E> AsyncRun<R>,CatchFunction<R,E>
- All Known Implementing Classes:
AsyncForEachRun
public interface Async<R>
An interface for asynchronous operations, providing utility methods
and constants related to asynchronous computations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ThreadLocal<CompletableFuture<Object>>A thread-local variable to store theCompletableFutureinstance for the current thread. -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<R>Gets theCompletableFutureinstance for the current thread.default Rresult()Blocks and retrieves the result of theCompletableFutureinstance for the current thread.default <T> voidsetCurCompletableFuture(CompletableFuture<T> completableFuture) Sets theCompletableFutureinstance for the current thread.static ThrowableExtracts the real cause of an exception wrapped by CompletionException.static CompletionExceptionWraps the incoming exception in a new CompletionException.
-
Field Details
-
CUR_COMPLETABLE_FUTURE
A thread-local variable to store theCompletableFutureinstance for the current thread.Note: After executing an asynchronous method, the thread stores the CompletableFuture of the asynchronous method in the thread's local variable
-
-
Method Details
-
setCurCompletableFuture
Sets theCompletableFutureinstance for the current thread.- Type Parameters:
T- The type of the result in the CompletableFuture- Parameters:
completableFuture- TheCompletableFutureinstance to be set
-
getCurCompletableFuture
Gets theCompletableFutureinstance for the current thread.- Returns:
- The
CompletableFutureinstance for the current thread, ornullif not set
-
result
Blocks and retrieves the result of theCompletableFutureinstance for the current thread.- Returns:
- The result of the CompletableFuture, or
nullif the thread was interrupted - Throws:
IOException- If the completion exception to the CompletableFuture is an IOException or a subclass of it
-
unWarpCompletionException
Extracts the real cause of an exception wrapped by CompletionException.- Parameters:
e- The incoming exception, which may be a CompletionException.- Returns:
- Returns the real cause of the original exception, or the original exception if there is no cause.
-
warpCompletionException
Wraps the incoming exception in a new CompletionException.- Parameters:
e- The incoming exception, which may be any type of Throwable.- Returns:
- Returns a new CompletionException with the original exception as its cause.
-