AsyncJavaHelpers
Entry points for calling the suspending and Flow-returning parts of the ADK from Java, and for bridging a Flow to Reactive Streams.
A suspend function compiles to a method with a trailing Continuation parameter, so Java passes the call as a lambda that forwards it. Kotlin default arguments are not visible to Java, so every parameter must be supplied:
Session session = AsyncJavaHelpers.await(c -> sessionService.createSession(key, null, c));
List<Event> events =
AsyncJavaHelpers.collect(runner.runAsync(user, id, null, message, null, null));A Flow also converts to a Reactive Streams Publisher, the common currency of RxJava, Project Reactor, and java.util.concurrent.Flow; the final hop is one line in caller code:
Flowable<Event> rx = Flowable.fromPublisher(AsyncJavaHelpers.asPublisher(flow)); // RxJava 3
Flux<Event> flux = Flux.from(AsyncJavaHelpers.asPublisher(flow)); // Reactor
Flow.Publisher<Event> jdk =
FlowAdapters.toFlowPublisher(AsyncJavaHelpers.asPublisher(flow)); // JDKKotlin callers should use the suspending APIs directly instead.
Functions
Exposes a fixed items sequence as a Publisher -- the Java-friendly way for a synchronous model or agent (extending a BasePublisher* base) to return already-computed values. Elements must be non-null; Reactive Streams forbids null.