parallelForEach

suspend fun <T> Iterable<T>.parallelForEach(concurrency: Int = Int.MAX_VALUE, action: suspend (T) -> Unit)

Runs action for every element concurrently and returns when all have finished.

At most concurrency actions run at the same time, limited by a Semaphore. The first failing action cancels the remaining work and its failure is rethrown to the caller.

Cancellation: cancelling the calling coroutine cancels every in-flight action before rethrowing.

Parameters

concurrency

the maximum number of concurrent actions, at least 1.

Throws