blob: b3191e8b09493cb533b009ee7d092c4c41db7a29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
package org.jetbrains.dokka.utilities
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
suspend inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> = coroutineScope {
map { async { f(it) } }.awaitAll()
}
suspend inline fun <A, B> Iterable<A>.parallelMapNotNull(crossinline f: suspend (A) -> B?): List<B> = coroutineScope {
map { async { f(it) } }.awaitAll().filterNotNull()
}
suspend inline fun <A> Iterable<A>.parallelForEach(crossinline f: suspend (A) -> Unit): Unit = coroutineScope {
map { async { f(it) } }.awaitAll()
}
|