Class AsyncExecutor

java.lang.Object
ai.acolite.agentsdk.core.runner.AsyncExecutor

public class AsyncExecutor extends Object
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 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 state
      shouldContinue - Predicate to check if iteration should continue
      operation - Function to execute on each iteration
      sideEffect - Side effect to run after each iteration (e.g., increment counter)
      Returns:
      CompletableFuture that resolves when iteration completes
    • memoize

      public static <T> Supplier<T> memoize(Supplier<T> supplier)
      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