Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardKotlincoroutine cancellation cooperationSingle-choice MCQ

Why does a tight CPU loop like `while (i < n) { i++ }` inside a coroutine fail to respond to `cancel()`, while inserting `ensureActive()` fixes it, even though no suspension point exists in either case?

launch { var i = 0 while (i < Int.MAX_VALUE) { i++ } // never cancels }