Programming Asynchronously

When programming modern applications we often have to make calls to remote services, update databases, perform searches, and the list goes on. Many of these tasks aren’t instantaneous. To improve program efficiency we may want to execute such operations asynchronously, in a non-blocking manner. Coroutines are intended to exactly solve that problem.

Starting Sequentially

Let’s create a program to go out and get the weather details to see if there are any delays at certain airports. As a first step, we’ll create an Airport class that will hold the data, along with a Weather class to hold the temperature. We’ll use the Klaxon library[26] to parse the JSON response from the Federal Aviation Administration (FAA) airport ...

Get Programming Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.