Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)
What is Cooperative Cancellation in Coroutines and how does yield() / ensureActive() work?
senior LevelPerformanceVue & Nuxt
In Simple Words:
Coroutine cancellation is cooperative: if a coroutine executes a tight CPU loop without calling suspending functions, it will not stop. Call ensureActive() or yield() periodically to check the cancellation flag.