mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[maven] parallel runner - do not start scope for single element
GitOrigin-RevId: 05e06b15ff3ba5deca5590575d41869914b83b9f
This commit is contained in:
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 {
|
||||
|
||||
Reference in New Issue
Block a user