single Thread Context
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.resourceScope
import arrow.fx.coroutines.singleThreadContext
import kotlinx.coroutines.withContext
import kotlinx.coroutines.ExecutorCoroutineDispatcher
suspend fun main(): Unit = resourceScope {
val single: ExecutorCoroutineDispatcher = singleThreadContext("single")
withContext(single) {
println("I am running on ${Thread.currentThread().name}")
}
}Content copied to clipboard
I am running on singleContent copied to clipboard
Deprecated
This API is being renamed in 2.x.x, use closeable builder instead
Replace with
import import arrow.fx.coroutines.singleThreadContext
Content copied to clipboard
singleThreadContext(name)Content copied to clipboard