How do I call to suspend functions and wait for bo...
# coroutines
c
How do I call to suspend functions and wait for both to finish, but execute both in parrallel?
Copy code
suspend fun getTwoThingsInParrallel():List<String> {
    apiService.oneLongTwo()
    apiService.secondLongCall()
      ...
//do something with the result
}
Like this? I thought awaitAll was sorta bad practice? https://stackoverflow.com/a/57458479/1048909
c
Copy code
suspend fun foo(): List<String> {
    coroutineScope {
        listOf(
            async { apiService.onLongTwo() },
            aynsc { apiService.secondLongCall() }
        ).awaitAll()
    }
}
I have not heard anyone say
awaitAll
is bad practice 🤔
The accepted answer in the SO linked you sent is better than my version btw, it doesn't need the list
k
The
coroutineScope
builder function is specifically for the parallel decomposition of work in conunction with
async
,
launch
and friends.
g
Why do you think it's a bad practice?