[maven] parallel runner - do not start scope for single element

GitOrigin-RevId: 05e06b15ff3ba5deca5590575d41869914b83b9f
This commit is contained in:
Alexander Bubenchikov
2023-12-11 12:27:38 +00:00
committed by intellij-monorepo-bot
parent 502793eddc
commit 21025d5b0d
@@ -14,12 +14,19 @@ import kotlinx.coroutines.awaitAll
class ParallelRunner(val project: Project, val cs: CoroutineScope) {
suspend fun <T> runInParallel(collection: Collection<T>, method: suspend (T) -> Unit) {
val runScope = cs.namedChildScope("ParallelRunner.runInParallel", Dispatchers.IO, true)
collection.map {
runScope.async {
method(it)
}
}.awaitAll()
if (collection.isEmpty()) return;
if (collection.size == 1) {
method.invoke(collection.first())
}
else {
val runScope = cs.namedChildScope("ParallelRunner.runInParallel", Dispatchers.IO, true)
collection.map {
runScope.async {
method(it)
}
}.awaitAll()
}
}
companion object {