AsyncJavaHelpers
object 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));Content copied to clipboard
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)); // JDKContent copied to clipboard
Kotlin callers should use the suspending APIs directly instead.