Hugo Costa
10/29/2024, 3:43 PMfun businessLogic(...) = runBlocking(Dispatchers.Default) {
val businessValue = async { someFunction() }
...
}
work but
suspended fun businessLogic(...): ReturnValue {
val businessValue = async { someFunction() }
...
}
doesn't? Doesn't the context from wherever this function is called carry over to allow for the async job to be launched?Sam
10/29/2024, 3:46 PMcoroutineScope
block:
suspend fun businessLogic(…): ReturnValue {
coroutineScope {
val businessValue = async { someFunction() }
…
}
}
The runBlocking
function implicitly creates a coroutine scope for its body code block, for convenience, which is why you don't need to do the same thing there.Hugo Costa
10/29/2024, 3:50 PMSam
10/29/2024, 3:53 PMHugo Costa
10/29/2024, 3:57 PMsuspend fun businessLogic(…) = coroutineScope {
val businessValue = async { someFunction() }
…
}
Make sense if that's the case 😅Hugo Costa
10/29/2024, 3:58 PM