Package ai.acolite.agentsdk.core.runner
Class AsyncExecutor
java.lang.Object
ai.acolite.agentsdk.core.runner.AsyncExecutor
AsyncExecutor
Utility for non-blocking iterative execution using CompletableFuture composition. Replaces blocking while loops with recursive async composition.
This separates Java concurrency concepts from agent execution logic.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CompletableFuture<T> iterateUntilWithSideEffect(T state, Predicate<T> shouldContinue, Function<T, CompletableFuture<T>> operation, Function<T, T> sideEffect) Execute an async operation iteratively with a side effect on each iteration.static <T> Supplier<T> Create a supplier that executes once and caches the result.
-
Constructor Details
-
AsyncExecutor
public AsyncExecutor()
-
-
Method Details
-
iterateUntilWithSideEffect
public static <T> CompletableFuture<T> iterateUntilWithSideEffect(T state, Predicate<T> shouldContinue, Function<T, CompletableFuture<T>> operation, Function<T, T> sideEffect) Execute an async operation iteratively with a side effect on each iteration.- Type Parameters:
T- The state type- Parameters:
state- The current stateshouldContinue- Predicate to check if iteration should continueoperation- Function to execute on each iterationsideEffect- Side effect to run after each iteration (e.g., increment counter)- Returns:
- CompletableFuture that resolves when iteration completes
-
memoize
Create a supplier that executes once and caches the result. Useful for expensive operations that should only run once.- Type Parameters:
T- The result type- Parameters:
supplier- The supplier to memoize- Returns:
- Memoized supplier
-