arrow-fx / arrow.fx.typeclasses / Concurrent / fork
abstract fun <A> Kind<F, A>.fork(ctx:
CoroutineContext
): Kind<F,
Fiber
<F, 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()
}
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
open fun <A> Kind<F, A>.fork(): Kind<F,
Fiber
<F, A>>
See Also
Do you like Arrow?
✖