Interface CompletableFutureAdapter


public interface CompletableFutureAdapter
SPI for adapting a single-value asynchronous type (e.g. Mutiny Uni, Reactor Mono) to and from CompletableFuture, which is the canonical asynchronous type used internally by AI Services.

It is used in two directions:

CompletableFuture and CompletionStage are handled natively and do not require an adapter. Implementations are discovered via the ServiceLoader mechanism.

Since:
1.20.0
  • Method Details

    • canAdapt

      boolean canAdapt(Type type)
      Parameters:
      type - the declared type (e.g. a @Tool method's return type, or an AI Service method's return type), such as Mono<String>.
      Returns:
      true if this adapter handles the given type.
    • toCompletableFuture

      CompletableFuture<?> toCompletableFuture(Object asyncValue)
      Converts a value of the adapted type (e.g. a Mono<T>) into a CompletableFuture. Invoked for @Tool methods returning the adapted type.
    • fromCompletableFuture

      Object fromCompletableFuture(Type type, CompletableFuture<?> future)
      Produces an instance of the adapted type (e.g. a Mono<T>) from a CompletableFuture. Invoked for AI Service methods declared to return the adapted type.
      Parameters:
      type - the declared type to produce (e.g. Mono<String>).
      future - the computed result.