September 2019
Intermediate to advanced
462 pages
11h 3m
English
The getAirportStatus() function is making synchronous calls, one at a time, to the getAirportData() function. If we receive a large number of airport codes, then making blocking calls, one by one, won’t be efficient. If we make the calls to getAirportData() asynchronous, using coroutines, then we can get a better throughput. Of course, we’ll have to test first and then write the code for asynchronous execution.
For getAirportStatus() to make asynchronous calls, we have to do three things. First, mark the function with the suspend keyword. Then execute the body of the function in the context of a Dispatchers.IO thread pool. Finally, embed the calls to getAirportData() within async calls and await for ...
Read now
Unlock full access