Using Kotlin Coroutines

Learn about the use of Kotlin coroutines and interchangeable functions.

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.

Get hands-on with 1400+ tech skills courses.