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

You want to run a non-cancellable cleanup (e.g. close a resource) in a `finally` block after the coroutine was cancelled, but the cleanup itself uses suspend calls. What is the correct internal reason `withContext(NonCancellable)` is required?

try { work() } finally { withContext(NonCancellable) { closeResourceSuspending() } }