Is there a way to write the Kotlin code below so that it compiles and works the same way on the JVM and in JavaScript?
fun <A: Any> request(request: Any): A = runBlocking {
suspendCoroutine<A> { cont ->
val subscriber = { response: A ->
cont.resume(response)
}
sendAsync(request, subscriber)
}
}
fun <Q : Any, A : Any> sendAsync(request: Q, handler: (A) -> Unit) {
// request is sent to a remote service,
// when the result is available it is passed to handler(... /* result */)
}
The code compiles and works fine when compiled to target the JVM. A compilation error is emitted when targeting JavaScript due to non-existent function runBlocking