Let's take a look at how we are waiting for each deferred to complete:
private fun asyncLoadNews() = launch {
val requests = mutableListOf<Deferred<List<String>>>()
feeds.mapTo(requests) {
asyncFetchHeadlines(it, dispatcher)
}
requests.forEach {
it.await()
}
...
}
Since we are using await() to wait for the completion of our coroutines, any exception happening inside them will be propagated to the current thread. This means that there are two scenarios in which the application will crash easily:
- There's no internet connection
- The URL of one or more feeds is invalid or incorrect
Let's test one of those out. We can add an invalid URL to the list of feeds, which is something like this:
private val feeds = listOf(
"https://www.npr.org/rss/rss.php?id=1001",
...