The first key term to introduce is suspension, which is the ability for an executing function to be paused and then resumed at a later date. This is achieved behind the scenes by using the continuations feature mentioned in the introduction. To indicate that a function is suspendable, the suspend keyword must be added to the function signature:
suspend fun delay(timeMillis: Long) { ... }
When an executing function is suspended, the compiler essentially saves the current execution point along with any local context it needs (locally scoped variables, for example). The object describing this state is relatively lightweight, and so it's perfectly possible to have hundreds of thousands or even millions of these objects active in memory in the same process. It would not be feasible to have the same number of threads. The lightweight nature of these objects...