Before coroutines, Android concurrency was a battlefield. You had AsyncTask — a class so error-prone it was deprecated in API 30. You had raw Threads, which you could create freely but couldn't cancel. Kotlin coroutines solve all of this.
suspend fun loadDashboard(): Dashboard {
val user = fetchUser()
val orders = fetchOrders()
return Dashboard(user, orders)
}What is a coroutine?
A coroutine is a unit of work that can be suspended and resumed without blocking a thread. When it hits a waiting operation, it suspends, releases the thread, and lets that thread pick up other work. Ten thousand coroutines can be simultaneously waiting while sharing just a handful of threads.
The Continuation — the secret extra parameter
Every suspend function you write gets silently transformed by the Kotlin compiler. This is called Continuation-Passing Style (CPS). The compiler adds a Continuation parameter at the end, which acts as a 'bookmark' for where the code should resume.