Understanding Kotlin coroutines
Asynchronous programming is at the heart of mobile development. In order to write efficient applications, leveraging the async capabilities of the framework and language you are using makes all the difference.
Coroutines are my absolute favorite language feature of Kotlin because of their expressiveness and how easy it is to express your asynchronous development needs in a concise way.
In this section, we will be covering the basic concepts of coroutines and compare them to Swift's async/await and Combine patterns.
Suspend functions
Coroutines are basically suspendable tasks that can suspend and resume execution, and they are not bound to any particular thread.
When you're writing asynchronous code, you generally need to think about the following two things:
- Which task needs asynchronous attention and has to be suspendable
- How you combine asynchronous tasks with the rest of your code
Let's see how you...