Kotlin offers a better way to perform asynchronous tasks, called coroutines. Coroutines are a new and fluent way of writing asynchronous and non-blocking code in Kotlin. They are much lighter than threads and are easy to manage. Both coroutines and threads are multitasking, but they differ in that threads are managed by the kernel and coroutines are managed by the code itself, thereby giving programmatic control.
Coroutines were introduced in Kotlin 1.1 as an experimental feature. There are two types of coroutines:
- Stackful
- Stackless
A stackful coroutine is a normal function that can be suspended during execution. It will be suspended with its entire stack, including its local variables, and the parameters passed from ...