supervisorScope

suspend fun <R> supervisorScope(block: suspend CoroutineScope.() -> R): R(source)

Creates a CoroutineScope with SupervisorJob and calls the specified suspend block with this scope. The provided scope inherits its coroutineContext from the outer scope, using the Job from that context as the parent for the new SupervisorJob. This function returns as soon as the given block and all its child coroutines are completed.

Unlike coroutineScope, a failure of a child does not cause this scope to fail and does not affect its other children, so a custom policy for handling failures of its children can be implemented. See SupervisorJob for additional details.

If an exception happened in block, then the supervisor job is failed and all its children are cancelled. If the current coroutine was cancelled, then both the supervisor job itself and all its children are cancelled.

The method may throw a CancellationException if the current job was cancelled externally, or rethrow an exception thrown by the given block.