Coordinate cancellation in Kotlin coroutines
8 steps · about 4 h 50 min · Intermediate
- Launch work inside a structured scope (reference, kotlinx.coroutines API, 35 min)
A scope makes child lifetime part of the surrounding operation.
- Choose execution context deliberately (reference, kotlinx.coroutines API, 35 min)
Dispatchers separate CPU work, blocking I/O and inherited context.
- Make cancellation cooperative (guide, Kotlin documentation, 35 min)
Suspension points and checks let unwanted work stop promptly.
- Predict exception propagation (reference, kotlinx.coroutines API, 35 min)
Builders and parent-child relationships determine which failure reaches which owner.
- Compose sequential and concurrent operations (reference, kotlinx.coroutines API, 30 min)
Async should represent intentional concurrency rather than become a default wrapper.
- Stream changing values with Flow (guide, Kotlin documentation, 40 min)
Cold flows combine cancellable production with declarative transformations.
- Protect shared mutable state (reference, kotlinx.coroutines API, 40 min)
Confinement, atomics and mutexes solve different contention patterns.
- Test virtual time and cancellation (reference, kotlinx.coroutines API, 40 min)
A test scheduler makes delays, completion and cleanup deterministic.