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

jivimberg

11/06/2018, 3:40 PM
Hi guys! I’m wondering if there’s a way of writing this code so I can schedule all operations and exit the
map
block (i.e. get to line 9) and then wait for the result. Right now the
await()
on line 6 is preventing me to do that. Using
CoroutineStart.LAZY
works but then I don’t get the nice parallel execution because each async only starts when it’s needed.
a

Alexander

11/06/2018, 4:40 PM
I replaced
downloadContent
function with
delay(500)
, added time measuring and got:
Copy code
Lanch jobs time: 50
Wait jobs time: 562
Total time: 656
So I think that is what you expected to see.
j

jivimberg

11/06/2018, 5:07 PM
They do execute in parallel if that’s what you’re referring to. But I’d like to be able to schedule both operations and get to line 9 regardless of the status of the operations, which in my original code it’s not happening.
a

Alexander

11/06/2018, 5:24 PM
Can you add time measuring that I could understand what do you want?
j

jivimberg

11/06/2018, 5:57 PM
I added some logging and it seems like the
await()
call on line 6 is not blocking the main coroutine execution as I initially thought. Was working as intended all along
Thanks for helping me get to the bottom of this!