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