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 Details

    • CUR_COMPLETABLE_FUTURE

      static final ThreadLocal<CompletableFuture<Object>> CUR_COMPLETABLE_FUTURE
      A thread-local variable to store the CompletableFuture instance 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

      default <T> void setCurCompletableFuture(CompletableFuture<T> completableFuture)
      Sets the CompletableFuture instance for the current thread.
      Type Parameters:
      T - The type of the result in the CompletableFuture
      Parameters:
      completableFuture - The CompletableFuture instance to be set
    • getCurCompletableFuture

      default CompletableFuture<R> getCurCompletableFuture()
      Gets the CompletableFuture instance for the current thread.
      Returns:
      The CompletableFuture instance for the current thread, or null if not set
    • result

      default R result() throws IOException
      Blocks and retrieves the result of the CompletableFuture instance for the current thread.
      Returns:
      The result of the CompletableFuture, or null if the thread was interrupted
      Throws:
      IOException - If the completion exception to the CompletableFuture is an IOException or a subclass of it
    • unWarpCompletionException

      static Throwable unWarpCompletionException(Throwable e)
      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

      static CompletionException warpCompletionException(Throwable e)
      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.