Hi, why not create the dispatcher within the extension function?
Like:
fun <T, R> Iterable<T>.map(
concurrency: Int,
transform: (T) -> R
): List<R> = runBlocking {
val dispatcher = Executors.newFixedThreadPool(concurrency).asCoroutineDispatcher()
//...
That way we do not need semaphores, but can limit the thread count for each call to the extension function.
Some Random Dude