Class AsyncUtils

java.lang.Object
io.reacted.patterns.AsyncUtils

@Immutable
public final class AsyncUtils
extends java.lang.Object
  • Method Summary

    Modifier and Type Method Description
    static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, PayloadT firstArgument, long iterations, java.util.function.Function<java.lang.Throwable,​java.util.concurrent.CompletionStage<PayloadT>> onError, java.util.concurrent.Executor asyncExecutor)
    Asynchronously executes operation iterations times.
    static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, PayloadT firstArgument, java.util.function.Function<java.lang.Throwable,​java.util.concurrent.CompletionStage<PayloadT>> onError, long iterations)
    Asynchronously executes operation iterations times.
    static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, PayloadT firstArgument, PayloadT onErrorAlternative, long iterations)
    Asynchronously executes operation iterations times.
    static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, PayloadT firstArgument, PayloadT onErrorAlternative, long iterations, java.util.concurrent.Executor asyncExecutor)
    Asynchronously executes operation iterations times.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • asyncLoop

      public static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, @Nullable PayloadT firstArgument, @Nullable PayloadT onErrorAlternative, long iterations)
      Asynchronously executes operation iterations times. Every loops iteration begins when the previous one is terminated. Silently ignore the errors and on error it maps the result of the iteration to onErrorAlternative
      Type Parameters:
      PayloadT - input type for the operation
      Parameters:
      operation - operation to be ran in async
      firstArgument - argument for the first call
      onErrorAlternative - if the step results into an exception, provide this value as input for the next stage
      iterations - a positive number of iterations to be executed
      Returns:
      a CompletionStage<PayloadT> that is going to contain the output of the last operation
      Throws:
      java.lang.IllegalArgumentException - if iterations is negative
    • asyncLoop

      public static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, @Nullable PayloadT firstArgument, java.util.function.Function<java.lang.Throwable,​java.util.concurrent.CompletionStage<PayloadT>> onError, long iterations)
      Asynchronously executes operation iterations times. Every loops iteration begins when the previous one is terminated
      Type Parameters:
      PayloadT - input type for the operation
      Parameters:
      operation - operation to be ran in async
      firstArgument - argument for the first call
      onError - mapper to handle exceptions in the middle of the loop
      iterations - a positive number of iterations to be executed
      Returns:
      a CompletionStage<PayloadT> that is going to contain the output of the last operation
      Throws:
      java.lang.IllegalArgumentException - if iterations is negative
    • asyncLoop

      public static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, @Nullable PayloadT firstArgument, @Nullable PayloadT onErrorAlternative, long iterations, java.util.concurrent.Executor asyncExecutor)
      Asynchronously executes operation iterations times. Every loops iteration begins when the previous one is terminated. Silently ignore the errors and on error it maps the result of the iteration to onErrorAlternative
      Type Parameters:
      PayloadT - input type for the operation
      Parameters:
      operation - operation to be ran in async
      firstArgument - argument for the first call
      iterations - a positive number of iterations to be executed
      onErrorAlternative - mapper to handle exceptions in the middle of the loop
      asyncExecutor - async executor used to run the loop
      Returns:
      a CompletionStage<PayloadT> that is going to contain the output of the last operation
      Throws:
      java.lang.IllegalArgumentException - if iterations is negative
    • asyncLoop

      public static <PayloadT> java.util.concurrent.CompletionStage<PayloadT> asyncLoop​(java.util.function.Function<PayloadT,​java.util.concurrent.CompletionStage<PayloadT>> operation, @Nullable PayloadT firstArgument, long iterations, java.util.function.Function<java.lang.Throwable,​java.util.concurrent.CompletionStage<PayloadT>> onError, java.util.concurrent.Executor asyncExecutor)
      Asynchronously executes operation iterations times. Every loops iteration begins when the previous one is terminated
      Type Parameters:
      PayloadT - input type for the operation
      Parameters:
      operation - operation to be ran in async
      firstArgument - argument for the first call
      iterations - a positive number of iterations to be executed
      onError - mapper to handle exceptions in the middle of the loop
      asyncExecutor - async executor used to run the loop
      Returns:
      a CompletionStage<PayloadT> that is going to contain the output of the last operation
      Throws:
      java.lang.IllegalArgumentException - if iterations is negative