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.
Really cool thing to know! thanks for sharing.
Erick S
Nice article! So in practical, what differs Semaphore vs limitedparallelism usage Shreyas Patil?