Class SupplierHelper

java.lang.Object
io.helidon.faulttolerance.SupplierHelper

public class SupplierHelper extends Object
Helper to handle async suppliers that return CompletionStage.
  • Method Details

    • toSyncSupplier

      public static <T> Supplier<T> toSyncSupplier(Supplier<? extends CompletionStage<T>> supplier, long timeout, TimeUnit unit)
      Maps a supplier returning a CompletionStage<T> to a supplier returning T by waiting on the stage; interruption of the calling thread during that wait restores its interrupt status before propagation as SupplierException, while an InterruptedException reported by the stage does not modify the calling thread's interrupt status.
      Type Parameters:
      T - type produced by supplier
      Parameters:
      supplier - the async supplier
      timeout - time to wait
      unit - unit of time
      Returns:
      the supplier
    • toRuntimeException

      public static RuntimeException toRuntimeException(Throwable t)
      Wraps a Throwable in a RuntimeException of type SupplierException if necessary. Will never nest SupplierExceptions.
      Parameters:
      t - the throwable
      Returns:
      the exception
    • unwrapThrowable

      public static Throwable unwrapThrowable(Throwable t)
      Gets the underlying cause of a SupplierException or of a ExecutionException.
      Parameters:
      t - the throwable
      Returns:
      the cause or the same throwable