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:
- A
@Toolmethod that returns such a type —toCompletableFuture(Object)normalizes the returned value so the asynchronous tool loop can compose it without blocking. - An AI Service method declared to return such a type —
fromCompletableFuture(Type, CompletableFuture)produces an instance of the declared type from the computed result.
CompletableFuture and CompletionStage are handled natively and do not
require an adapter. Implementations are discovered via the ServiceLoader mechanism.
- Since:
- 1.20.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanfromCompletableFuture(Type type, CompletableFuture<?> future) Produces an instance of the adapted type (e.g. aMono<T>) from aCompletableFuture.toCompletableFuture(Object asyncValue) Converts a value of the adapted type (e.g. aMono<T>) into aCompletableFuture.
-
Method Details
-
canAdapt
- Parameters:
type- the declared type (e.g. a@Toolmethod's return type, or an AI Service method's return type), such asMono<String>.- Returns:
trueif this adapter handles the given type.
-
toCompletableFuture
Converts a value of the adapted type (e.g. aMono<T>) into aCompletableFuture. Invoked for@Toolmethods returning the adapted type. -
fromCompletableFuture
Produces an instance of the adapted type (e.g. aMono<T>) from aCompletableFuture. 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.
-