https://kotlinlang.org logo
#getting-started
Title
# getting-started
l

Loney Chou

07/12/2022, 5:57 AM
I have a function that runs on main thread, which cannot be modified, like this:
Copy code
fun calculate(): Int
And inside it I need to call a suspend function. How to do that?
runBlocking
?
r

Robert Williams

07/12/2022, 9:06 AM
Depends whether completion of the suspend fun is required to determine the
Int
result
If so, you'll need
runBlocking
Otherwise consider passing a Scope and launching another coroutine as a side-effect
l

Loney Chou

07/12/2022, 9:29 AM
Thanks 😉
That suspend function is the underlying calculation on another thread
r

Robert Williams

07/12/2022, 9:50 AM
Well there's literally no reason to do it on another thread if you're going to block the main thread anyway
2 Views