/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package org.jetbrains.dokka.utilities
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.jetbrains.dokka.InternalDokkaApi
@InternalDokkaApi
public suspend inline fun Iterable.parallelMap(crossinline f: suspend (A) -> B): List = coroutineScope {
map { async { f(it) } }.awaitAll()
}
@InternalDokkaApi
public suspend inline fun Iterable.parallelMapNotNull(crossinline f: suspend (A) -> B?): List = coroutineScope {
map { async { f(it) } }.awaitAll().filterNotNull()
}
@InternalDokkaApi
public suspend inline fun Iterable.parallelForEach(crossinline f: suspend (A) -> Unit): Unit = coroutineScope {
forEach { launch { f(it) } }
}