Hi, I'm calling a proxy from a suspend function ``...
# coroutines
g
Hi, I'm calling a proxy from a suspend function
Copy code
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
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
thx, I'll check that