Class AsyncUtil


  • public final class AsyncUtil
    extends Object
    Utility class to wrap an asynchronous call and catch all errors.
    • Method Detail

      • invoke

        public static <T> CompletableFuture<T> invoke​(AsyncCallable<T> body)
        Invoke the body and return the response wrapped as a completable future..
      • invoke

        public static <T> CompletableFuture<T> invoke​(boolean logError,
                                                      AsyncCallable<T> body)
        Invoke the body and return the response wrapped as a completable future..
      • expectErrorInTimeoutOrStopWaiting

        public static void expectErrorInTimeoutOrStopWaiting​(@NotNull
                                                             @NotNull Long timeout,
                                                             @NotNull
                                                             @NotNull TimeUnit unit,
                                                             @NotNull
                                                             @NotNull CompletableFuture<?> future)
        This call waits the provided timeout for an error to occur. After the timeout, this call continues with the flow without waiting for the actual result. This is to prevent waiting for backend calls to return, while we are not interested in the return value for the current flow. (e.g. send mail via BSL). The assumption is that if no error is returned within the timeout, the call will be successful. Delegates to CompletableFuture.get(long, TimeUnit)}.