Introducing Kotlin coroutines
Coroutines are part of the Kotlin API. They introduce a new and easier way of handling async work and concurrency jobs.
Often, with Android, we need to run or execute different tasks behind the scenes. In the meantime, we don't want to block the main thread of the application and get an unresponsive UI.
To mitigate this issue, coroutines allow you to execute async work much easier while providing main-thread safety for your Android apps. You can use the Coroutines API by launching one coroutine, or more, depending on your needs.
In this section, we will cover three essential questions about the Coroutines API that derive from what we stated earlier:
- What is a coroutine?
- What are the features and advantages of coroutines?
- How do coroutines work?
Let's jump in!
What is a coroutine?
A coroutine is a concurrency design pattern for async work. A coroutine represents an instance of suspendable computation.
In...