Ensures Active Coroutine
Marks suspend functions that ensureActive.
CancellationException is the signal used by Kotlin's structured concurrency model to cancel a coroutine, and must be rethrown when the coroutine is no longer active. Because CancellationException has subclasses that represent real domain exceptions, a simple is-check is not sufficient — ensureActive is required.
Functions bearing this annotation implement the pattern below:
try { /* ... */} catch (e: Exception) {
if (e is CancellationException) currentCoroutineContext().ensureActive()
// safe to handle or swallow e here
}Content copied to clipboard
Supporting functions: nullableOf, resultOf, outcomeOf, maybeOf, faultOf, catchStringOf, catchExceptionOf, RaiseScope.catching, RaiseScope.folding.