July 2018
Intermediate to advanced
266 pages
7h 11m
English
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:
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 =
Read now
Unlock full access