Ismaïl
03/25/2023, 1:08 PMPatrick Steiger
03/26/2023, 12:45 AMloadUsers
is suspend, caller expects it to return the result by the time it returns (obviously, as the result is literally returned, right?). If it needs to run stuff in parallel to do it’s work, it’s correct to open a scope inside it
suspend fun loadUsers(): List<User> {
coroutineScope {
//...
}
}
suspend fun loadUsers(): List<User> {
CoroutineScope(Dispatchers.Default).run {
//...
}
}
suspend fun CoroutineScope.loadUsers(): List<User> {
//...
}
coroutineScope {}
Ismaïl
03/26/2023, 5:19 PM