If I have a list of Deferred's created inside a `s...
# coroutines
m
If I have a list of Deferred's created inside a
supervisorScope
using
async
. What is the most efficient way to await for the first failure of any of the jobs? At the moment I am looping the jobs, saving away successes, and capturing the first failure, then when that happens issuing a "controlled cancellation on the others" and using a yield (or delay) inside the tight loop, but it feels like there must be a better way of doing this
coroutineScope
doesn't work for me here because depending on input I need to either allow the remaining jobs to complete, or force them to fail.
e
awaitAll() will throw the first exception if any
then you can simply cancel all rest, it's a no-op if a job is already complete
m
👍
Thanks!
Not sure how I didn't run into awaitAll
Yep this worked well for my use case, converted about 40 lines of code to 10