fixedThreadPoolContext

suspend fun ResourceScope.fixedThreadPoolContext(nThreads: Int, name: String): ExecutorCoroutineDispatcher(source)

Creates a single threaded CoroutineContext as a Resource. Upon release an orderly shutdown of the ExecutorService takes place in which previously submitted tasks are executed, but no new tasks will be accepted.

import arrow.fx.coroutines.fixedThreadPoolContext
import arrow.fx.coroutines.resourceScope
import kotlinx.coroutines.withContext
import kotlinx.coroutines.ExecutorCoroutineDispatcher

suspend fun main(): Unit = resourceScope {
val pool: ExecutorCoroutineDispatcher = fixedThreadPoolContext(8, "custom-pool")
withContext(pool) {
println("I am running on ${Thread.currentThread().name}")
}
}
I am running on custom-pool-1

fun fixedThreadPoolContext(nThreads: Int, name: String): Resource<ExecutorCoroutineDispatcher>(source)