I've got the `handleCall(): Result = ...` interfac...
# coroutines
r
I've got the
handleCall(): Result = ...
interface to implement, how would I invoke suspend functions in there? Via
runBlocking
?
s
Yup, When bridging from the asynchronous (suspend) world to the synchronous world,
runBlocking
is your friend.
k
If the function is not marked as suspend, then your only option is to block. Be careful, though, because invoking
runBlocking
from another suspending function can result in deadlock
r
Makes sense, don't cross the streams.
🤣 1
z
Also if you call runBlocking from a thread that’s running some kind of message loop, and you call a suspend function that dispatches to that thread, it may deadlock (common in android).
r
So open a new Thread for the message loop? Is there a way I can tell coroutines to open a new thread for me, or should I use the
Thread
API?
z
Didn’t mean that. It’s just virtually impossible to use runBlocking in a way that is perfectly safe.