Hi, if I for loops async { }, is there a guarantee...
# coroutines
u
Hi, if I for loops async { }, is there a guarantee of order of them starting to run? I have a semaphore inside them, but it seems race-y
o
No, I don't think there is a guaranteed order
z
Nope, there is no ordering guarantee. If you need explicit ordering though, you can implement it manually.
u
Ok makes sense, how would I go about doing that? Blocking queue?
z
If by “blocking queue” you mean
Channel
, then yes, that’s one way 😉
(
Channel
is effectively a blocking suspending queue)
u
sorry im coroutine newb. Ive seen channels used to pipe data, but it seems I want to pipe lazy Deffered instances and start them in the receiver?
z
You could do that, or you could just send suspend functions through your channel directly, and have your receiver do the
async
part
u
hm, but doesnt that make the start of the async race-y again?
z
true.
start = UNDISPATCHED
might be better here, no channel required,
u
interesting, the way I read the docs is the async body going to actually get executed synchronously until first susp. point, correct?you think I can rely on that?
z
yep