In this section, we will show several examples of how to use coroutines effectively in real-world scenarios. The coroutine world will frequently have to interface with the blocking world, and so we will cover several integration techniques.
Coroutines in action
Concurrent HTTP requests
Ktor is a HTTP library that was developed by Jetbrains which offers both client and server side components. The client side component allows you to make HTTP requests using suspendable functions.
In the following example, we will make several HTTP requests concurrently, returning the combined results in the form of a List:
suspend fun multiTemp(cities: List<String>): List<String> {
val temps = cities.map {
coroutineScope {
...