supervisedAll

suspend fun <T> Iterable<suspend () -> T>.supervisedAll(concurrency: Int = Int.MAX_VALUE): List<Result<T>>(source)

Runs every suspending task concurrently, isolating failures, and returns one Result per task in input order (supervisorScope + async).

A failing task never cancels its siblings. If the caller itself is cancelled, the CancellationException is rethrown instead of being captured. A task that throws its own CancellationException while the caller is still active is captured as a failure.

concurrency limits how many tasks run at once (default: unlimited); it must be greater than zero.

When the caller's context has a TraceSpan, the tasks run in one child span named "supervisedAll"; otherwise nothing changes.

Example:

val results = listOf<suspend () -> Item>({ api.a() }, { api.b() }).supervisedAll()
val ok = results.mapNotNull { it.getOrNull() }

Rules: SCOPE_004 (use supervisorScope for independent failure semantics), CONCUR_003. See docs/BEST_PRACTICES_COROUTINES.md.

Requires opting in to ExperimentalStructuredCoroutines.

Receiver

the task factories to run.

Return

one Result per task, in input order. An empty receiver yields an empty list.

Parameters

concurrency

maximum number of tasks running at once; must be greater than zero.

See also

Throws

if the caller is cancelled.