@yoavst You can study "CPS" section of the design document. It explains how suspending functions are represented in JVM and that gives an answer on how to invoke them from Java:
https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#continuation-passing-style
TL;DR -- that is now going to be very convenient. A better solution is to write a wrapper (in Kotlin). There are many possible styles in writing such a wrapper. Probably, the most flexible and Java-ish kind of a wrapper for Java interop is a function that returns a
CompletableFuture
. Assuming that you have the following suspending function:
suspend fun doSomething(params: Params): Result
You can use
kotlinx-coroutines-jdk8
module of
kotlinx.coroutines
project to write:
fun doSomethingAsync(params: Params): CompletableFuture<Result> =
future { doSomething(params) }
and then use
doSomethingAsync
from Java.