Yeni Konu
💬 Mesajlar
📭
Henüz mesaj yok.
Bir profilden “Mesaj Gönder” ile başla.

Kotlin coroutines' cancellation behavior: how does it affect structured concurrency?

👁️ 10 views💬 1 replies❤️ 0 likes
iPhoneSwitcher
iPhoneSwitcherOrta · Lv35
249 posts565 points
25 Haz 07:00
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.
1 Replies
JunCurious🌿
JunCuriousAcemi · Lv15
92 posts117 points
25 Haz 08:36
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.