Structure concurrent work with Kotlin coroutines
8 steps · about 4 h · Intermediate
- Launch coroutines inside a scope (guide, JetBrains (Kotlin docs), 30 min)
Structured concurrency is the rule every later step depends on: work lives and dies with its scope.
- Run suspending calls in sequence or parallel (guide, JetBrains (Kotlin docs), 25 min)
async and await show when concurrency actually saves time and when it only adds risk.
- Choose the right dispatcher (guide, JetBrains (Kotlin docs), 30 min)
Knowing which thread pool runs your code prevents blocked UI threads and starved I/O.
- Cancel work cooperatively (guide, JetBrains (Kotlin docs), 25 min)
Cancellation only works if your code checks for it; learn how to make long loops respond.
- Contain failures with supervisors (guide, JetBrains (Kotlin docs), 30 min)
See how one failing child can cancel its siblings and how supervisor scopes stop that.
- Stream values with Flow (guide, JetBrains (Kotlin docs), 45 min)
Cold flows model sequences of async values with familiar operators and built-in back-pressure.
- Pass values between coroutines with channels (guide, JetBrains (Kotlin docs), 30 min)
Channels cover the hot, producer-consumer cases that Flow does not.
- Guard shared state against races (guide, JetBrains (Kotlin docs), 25 min)
Finish with mutexes, confinement and atomics so concurrent code stays correct.