https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

Ayfri

08/29/2021, 9:00 AM
Hi, if I have a suspend function where inside I execute a function which requires a lambda not suspend (I'm using a Java library), but I want to execute lambda things inside Do I have to add
runBlocking { //code }
everytime or is there a way to intercept the upper suspend ?
u

ursus

08/29/2021, 12:37 PM
turn your java async api into suspend function with
suspendCancelableCoroutine
z

Zach Klippenstein (he/him) [MOD]

08/29/2021, 10:49 PM
You can grab the coroutine context from the outer suspend function and launch coroutines on it from inside the non-suspend function. You can't join on those coroutines though. runBlocking could get you into trouble depending on which thread the non-suspend code is executing on.
4 Views