Coroutines! Gotta catch 'em all!
summary
Explains exactly how Kotlin coroutines fail and how to make them behave: structured concurrency scopes determine whether a child exception cancels siblings, use supervisor job or supervisorScope to isolate failures, use cooperative checks like isActive, yield or ensureActive for cancellation, convert callbacks with suspendCancellableCoroutine so network calls cancel, run cleanup inside withContext(NonCancellable), prefer lifecycle/viewModel scopes (they use supervisor jobs), and install a CoroutineExceptionHandler for uncaught errors so the app doesn’t unexpectedly die.
AI-written summary · about
chapters (9)
- 0:00Start
- 12:16CPU heavy computation that may exhaust thread-pool
- 18:08Handling Cancellation
- 20:27Cancellation of coroutine code needs to be cooperative!
- 20:51Understanding Exceptions
- 21:15The failure of a Job cancels the parent Job & other siblings
- 24:39The same happens with the coroutine scope builders: coroutineScope and supervisor Scope
- 27:27Check the implementation of predefined scopes!
- 35:46Supervisor Job to avoid propagating cancellation
related talks
42mWhy exception handling with Kotlin Coroutines is so hard, how to master it!
39mKotlin Coroutine Mechanisms
47mKotlin Coroutines
44mTesting Kotlin Coroutines
31mCoroutines Zero to Hero
42mWhy exception handling with Kotlin Coroutines is hard and how to master it!
11mKotlin Coroutines: Design and Implementation
43mCoroutines for Java Developers
