(I my real code, the runBlocking are processed fro...
# coroutines
g
(I my real code, the runBlocking are processed from a method.invoke to "wait", that why I can' t use suspend functions there) - How can I avoid this unexpected behvior?
m
what is the desired behavior? You want to execute launch block 1 and 2 sequentially ?
g
no, in parallel (of course here the implementation is simplified and do not have suspended functions, so it won't be the case)
m
so you want parallel with interleaving results?
g
yes
m
async{op1} async{op2} async1.await asyn2.await. Should do it?
you must call await only after declaring both async tho. otherwise it’s just sequential
are we talking about just 1 thread then ?
g
It's not possible in my implementation due to the complexity of the code. But my issue has been solved by using launch(Dispatcher.IO)
m
ok. A note tho, you should not rely in the apparent order of execution. Launching two coroutines and expecting multiple interchangeable results with a specific order cannot be guaranteed
it’s better to rethink the design of the code
g
Thx. I understand that.
u
@myanmarking he is not relying on order. He is expecting the shorter delay to finish first
m
ya, but you don’t have any guarantees. I am assuming the delay is some kind of computation