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
louiscad
08/16/2019, 8:38 PM
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.