Using Kotlin Coroutines
Explore how Kotlin coroutines allow you to write asynchronous code that suspends execution without blocking the main thread. Understand how to manage sequential and parallel API calls using coroutine builders like async and await, improving app responsiveness and performance.
We'll cover the following...
Coroutines
The core functionality that Kotlin coroutines introduce is the ability to suspend a coroutine at some point and resume it in the future. Thanks to that, we might run our code on the main thread and suspend it when we request data from an API. When a coroutine is suspended, the thread is not blocked and is free to go; therefore, it can be used to change the view or process other coroutines. Once the data is ready, the coroutine waits for the main thread (this is a rare situation, but there might be a queue of coroutines waiting for it). Once it gets the thread, it can continue from the point where it stopped.
This picture shows the updateNews(), and updateProfile() functions running on the main ...