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 {