https://kotlinlang.org logo
Title
g

Gilles Barbier

02/05/2021, 9:48 PM
Hi, I'm calling a proxy from a suspend function
suspend fun test() {
  o.method()
}
here,
o
is a proxy obtained by
Proxy.newProxyInstance(..., proxyHandler)
. So this will call the
invoke
method of
proxyHandler
. My question is: how can I propagate the suspend up to
proxyHandler
and use a suspend function from its
handle
method (without having to start a runBlocking of course) ?
j

jw

02/05/2021, 10:28 PM
The easiest way, weirdly, is to call the suspend function from Java. You can unpack the
Continuation
argument from the Proxy's
Object[]
and then invoke the suspend function from Java.
Note: this only works if
a.method()
is a
suspend fun
itself. Otherwise
runBlocking
is your only recourse.
g

Gilles Barbier

02/05/2021, 10:54 PM
thx, I'll check that