arrow-fx-coroutines / arrow.fx.coroutines / Resource / singleThreadContext

singleThreadContext

fun singleThreadContext(name: String): Resource<CoroutineContext>

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.*

val singleCtx = Resource.singleThreadContext("single")

suspend fun main(): Unit =
  singleCtx.use { ctx ->
    evalOn(ctx) {
      println("I am running on ${Thread.currentThread().name}")
    }
  }

Do you like Arrow?

Arrow Org
<