Is there a tidy way to wait for any of`n` coroutin...
# coroutines
m
Is there a tidy way to wait for any of`n` coroutines to finish (don’t care which one finishes first, just give me the first one)
l
You want a race of coroutines with only one winner, and losers cancelled?
m
No, the others keep going — I just want to respond as soon as the first one finishes and possibly add another coroutine to do yet more work
The goal is to keep some
k
tasks going, but I need to look at each as it finishes to know if I should add more work to do
l
@mp You can hack into an
actor
I think. You can launch 4 (or
k
) coroutines inside it that then call
receive()
in a
while(isActive)
loop before doing work with the received value.
m
interesting, I’ll look into it
a
It might be worth checking out the source for
AwaitAll
which does a similar thing: https://github.com/Kotlin/kotlinx.coroutines/blob/master/common/kotlinx-coroutines-core-common/src/Await.kt#L59
👍 1