arrow-fx / arrow.fx / IORace / raceTriple
open fun <A, B, C> raceTriple(ctx:
CoroutineContext
, ioA:
IOOf
<A>, ioB:
IOOf
<B>, ioC:
IOOf
<C>):
IO
<
RaceTriple
<
ForIO
, A, B, C>>
Race three tasks concurrently within a new IO. Race results in a winner and the others, yet to finish task running in a Fiber.
import arrow.fx.*
import arrow.fx.extensions.fx
import kotlinx.coroutines.Dispatchers
fun main(args: Array<String>) {
//sampleStart
val result = IO.fx {
val raceResult = !IO.raceTriple(Dispatchers.Default, never<Int>(), just("Hello World!"), never<Double>())
raceResult.fold(
{ _, _, _ -> "never cannot win before complete" },
{ _, winner, _ -> winner },
{ _, _, _ -> "never cannot win before complete" }
)
}
//sampleEnd
val r = result.unsafeRunSync()
println("Race winner result is: $r")
}
ctx
- CoroutineContext to execute the source IO on.
ioA
- task to participate in the race
ioB
- task to participate in the race
ioC
- task to participate in the race
Return RaceTriple
See Also
Do you like Arrow?
✖