I created a zipper for my Coroutines but it is not...
# coroutines
a
I created a zipper for my Coroutines but it is not executing my code parallely. It executes the two Coroutines sequentially can I have them work in parallel?
val a = async { doSomeA( ) }
val b = async { doSomeB( ) }
zipper( a.await( ), b.await( ) )
g
why do you need own
zipper
? There is
List<Deferred>.awaitAll()
for this Also what is your implementation and how you check it?
a
I just pass my results in a separate function and something with them. I can exchange it with awaitAll but will this make them execute parallelly.
g
could you please reproduce this first, maybe you have some other problem. Just create reproduction sample here that shows your problem https://play.kotlinlang.org/
will this make them execute parallelly
see, they will run concurrently, but it doesn’t mean they will run in parallel (this depends on type of opertion, dispatcher etc)
see, your code above will run async block concurrently, implementation is correct, I more interested why do you think it’s not concurrent, this is why I asked about reproduction, to understand your code better
m
Did you maybe test it by wrapping this code in
runBlocking
block?
a
I am putting a thread sleep I think maybe that could be the mistake
@gildor here is my code https://pl.kotl.in/afPZmjagm
m
if you put
delay(1)
after
print
you'll get different results - your loop completes too soon for treading to be noticed
g
Correct, as Marko said, your first async is just too fast, so by time you start second async first already finished, just add delay() or thread.sleep or anything else to slowdown first async
a
Aaah I got it thanks @gildor and @Marko Mitic 😄 it worked :)