From 21025d5b0d7343fa07ed33da6cc0e8838275e0f3 Mon Sep 17 00:00:00 2001 From: Alexander Bubenchikov Date: Mon, 11 Dec 2023 10:59:11 +0100 Subject: [PATCH] [maven] parallel runner - do not start scope for single element GitOrigin-RevId: 05e06b15ff3ba5deca5590575d41869914b83b9f --- .../idea/maven/utils/ParallelRunner.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/ParallelRunner.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/ParallelRunner.kt index d0ec678b98ac..c34b6b8ca0c3 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/ParallelRunner.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/ParallelRunner.kt @@ -14,12 +14,19 @@ import kotlinx.coroutines.awaitAll class ParallelRunner(val project: Project, val cs: CoroutineScope) { suspend fun runInParallel(collection: Collection, 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 {