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

myanmarking

10/19/2018, 6:15 PM
guys, what is the best way to wait all results of async calls inside a for loop ?
a

apoorv9990

10/19/2018, 6:18 PM
create a list of the async calls and use awaitAll
m

myanmarking

10/19/2018, 6:19 PM
sth like this:
Copy code
val list = it.map { async { ... } }
and then
Copy code
awaitAll()
n

Nikky

10/19/2018, 6:28 PM
if you have a loop, just do the loop within a coroutineScope
the scope will not exit until all the jobs are done
g

gildor

10/20/2018, 9:04 AM
You cannot get result if you just run and forget in coroutineScope.
awaitAll is correct solution
n

Nikky

10/20/2018, 9:25 AM
oh right, they mentioned the result.. derp
3 Views