Practical Patterns for Kotlin Coroutines in Production
summary
Practical, actionable rules for Kotlin coroutines: never use async immediately await is pointless — start asyncs together and await later or use coroutineScope; prefer external scopes for fire-and-forget; handle cancellation as structured concurrency so use supervisorScope for independent children and avoid creating children in a scope that must await them; for cleanup use NonCancellable and never silence cancellation — don't swallow CancellationException; convert callbacks with suspendCancellableCoroutine or use callbackFlow + awaitClose for multi-value callbacks and wrap blocking IO with dedicated dispatchers.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:06Sync vs async calls with coroutines
- 3:16Parent-child coroutine scopes
- 6:12Cancellation mechanisms
- 9:21Supervisor scope basics
- 10:25Blocking ops in coroutines
- 11:31Non-cancellable cleanup
- 12:36Exception handling pitfalls
- 13:40Callback to suspend conversion
- 15:48Blocking APIs with Dispatchers.IO
- 17:34Sync with limited dispatchers
- 18:58Job join for completion
- 19:41CompletableDeferred sync
- 22:19Flow patterns optimization
- 24:46StateFlow vs SharedFlow
- 27:42Quiz & Q&A
related talks
44mTesting Kotlin Coroutines
47mKotlin Coroutines
42mKotlin Coroutines: An Intro to Practical Use on Android
37mCoroutines! Gotta catch 'em all!
30mBetter asynchronous programming with Kotlin Coroutines
59mKotlin coroutines: new ways to do asynchronous programming
40mConcurrency made easy with Kotlin Coroutines
49mLaunching Into Coroutines
