Package io.reacted.patterns
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 executesoperationiterationstimes.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 executesoperationiterationstimes.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 executesoperationiterationstimes.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 executesoperationiterationstimes.
-
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 executesoperationiterationstimes. Every loops iteration begins when the previous one is terminated. Silently ignore the errors and on error it maps the result of the iteration toonErrorAlternative- Type Parameters:
PayloadT- input type for the operation- Parameters:
operation- operation to be ran in asyncfirstArgument- argument for the first callonErrorAlternative- if the step results into an exception, provide this value as input for the next stageiterations- 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- ifiterationsis 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 executesoperationiterationstimes. 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 asyncfirstArgument- argument for the first callonError- mapper to handle exceptions in the middle of the loopiterations- 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- ifiterationsis 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 executesoperationiterationstimes. Every loops iteration begins when the previous one is terminated. Silently ignore the errors and on error it maps the result of the iteration toonErrorAlternative- Type Parameters:
PayloadT- input type for the operation- Parameters:
operation- operation to be ran in asyncfirstArgument- argument for the first calliterations- a positive number of iterations to be executedonErrorAlternative- mapper to handle exceptions in the middle of the loopasyncExecutor- 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- ifiterationsis 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 executesoperationiterationstimes. 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 asyncfirstArgument- argument for the first calliterations- a positive number of iterations to be executedonError- mapper to handle exceptions in the middle of the loopasyncExecutor- 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- ifiterationsis negative
-