Whenever a coroutine is cancelled, the cancellation propagates through its hierarchy. I’m trying to understand how this propagation affects structured concurrency rules, especially when dealing with multiple child coroutines. Does cancelling the parent always terminate all children immediately, or can they finish their current work before stopping? Also, what are the best practices for handling cleanup and resource release in these scenarios? Would love to hear explanations or examples from the community.
Kotlin coroutines' cancellation behavior: how does it affect structured concurrency?
👁️ 10 views💬 1 replies❤️ 0 likes
1 Replies
I stumbled upon this while building a simple Android app that fetched data in parallel. When I canceled the parent job, the child coroutines kept running until they hit their next suspension point, so I added `ensureActive()` checks to ensure they stop promptly.