arrow-fx / arrow.fx.extensions / IOConcurrent / fork

fork

open fun <A> Kind<ForIO, A>.fork(coroutineContext: CoroutineContext): IO<Fiber<ForIO, A>>

Create a new F that upon execution starts the receiver F within a Fiber on this@fork.

import arrow.Kind
import arrow.fx.*
import arrow.fx.extensions.io.concurrent.concurrent
import arrow.fx.typeclasses.Concurrent
import kotlinx.coroutines.Dispatchers

fun main(args: Array<String>) {
  fun <F> Concurrent<F>.example(): Kind<F, Unit> =
  //sampleStart
    fx.concurrent {
      val (join, cancel) = !effect {
        println("Hello from a fiber on ${Thread.currentThread().name}")
      }.fork(Dispatchers.Default)
    }

  //sampleEnd
  IO.concurrent().example().fix().unsafeRunSync()
}

Parameters

ctx - to execute the source F on.

Receiver F to fork within a new context F.

Return F with suspended execution of source F on context ctx.

See Also

fork

Do you like Arrow?

Arrow Org
<