hello, was wondering if there is some nice idiomat...
# coroutines
d
hello, was wondering if there is some nice idiomatic way of error handling for awaiting for a list of deferred to complete, e.g.
awaitAll
will throw first encountered exception Is there a better way than
Copy code
val results: List<Deferred<Any>> = ... // whatever
results.joinAll()
for (result in results) {
  val error = result.getCompletionExceptionOrNull()
  if (error != null) {
    // handle error
  } else {
    result.await()
  }
}
l
Either you handle errors outside of the local
coroutineScope { … }
inside which you start your `async`/`launch` child coroutines, or you handle errors inside the `async`/`launch` blocks themselves, recovering and letting other coroutines of the scope continue to execute.
d
👍 doing the
try/catch
within
async
block should do the trick, then i can just do
awaitAll()