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

gildor

09/14/2017, 7:30 AM
@anthonyandroid Please check this section of official coroutine guide - https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#concurrent-using-async Also you can check sample from kotlin-coroutines-retrofit (you can use this approach for any coroutine): https://github.com/gildor/kotlin-coroutines-retrofit#parallel-requests
👏 1
a

anthonyandroid

09/14/2017, 7:32 AM
so your suggestion is to use
await()
for each job I have, to make sure that all the jobs are completed?
just saw the edit, I will take a look. 😉 thx andrey !
g

gildor

09/14/2017, 7:36 AM
General idea: build all the coroutines using
async
and when you build and start all of them (they started by default) you just call
await()
on all of them, so when last coroutine finished you will get your results
You can use launch as well, to run some tasks in parallel, but you cannot get results from Job
a

anthonyandroid

09/14/2017, 7:43 AM
You are right; I was trying to call
start
for every job but now it looks nonsense. They should be started automatically and that sounds faster
g

gildor

09/14/2017, 7:47 AM
Yeah, check
start
argument of
async
, you can see that async starts by default https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/async.html
a

anthonyandroid

09/14/2017, 7:52 AM
very nice. thank u!
3 Views