Coroutines

6 concepts · 10 practice questions

Suspend functions

A suspend function can pause and resume without blocking its thread. The compiler adds a hidden Continuation parameter; it can only be called from a coroutine or another suspend function.

suspend fun loadProfile(): Profile {
    val user = api.fetchUser()   // suspends, thread is free
    return Profile(user)
}

Also covered

Dispatchers
Structured concurrency
Cooperative cancellation
Flow basics
StateFlow & lifecycle

Sign in to read the rest and take the 10-question test.

Sign in to continue