arrow-fx-coroutines / arrow.fx.coroutines / raceTriple
suspend fun <A, B, C> ~~raceTriple~~(fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C):
RaceTriple
<A, B, C>
Deprecated: Will be removed since it leaks Fiber, and breaks structured concurrency. Replace with select
suspend fun <A, B, C> ~~raceTriple~~(ctx:
CoroutineContext
, fa: suspend () -> A, fb: suspend () -> B, fc: suspend () -> C):
RaceTriple
<A, B, C>
Deprecated: Will be removed since it leaks Fiber, and breaks structured concurrency. Replace with select
Races three tasks concurrently within a new suspend fun. Race results in a winner and the others, yet to finish tasks running in Fiber.
import arrow.fx.coroutines.*
suspend fun main(): Unit {
//sampleStart
val res = raceTriple({ never<Int>() }, { never<Int>() }, { "Hello World!" })
val r = when(res) {
is RaceTriple.First -> "never cannot win race"
is RaceTriple.Second -> "never cannot win race"
is RaceTriple.Third -> res.winner
}
//sampleEnd
println("Race winner result is: $r")
}
ctx
- CoroutineContext to execute the source fa, fb & fc on.
fa
- task to participate in the race
fb
- task to participate in the race
fc
- task to participate in the race
Return either RaceTriple.First with product of the winner’s result ƒa and still running tasks fb & fc, or RaceTriple.Second with product of running tasks ƒa & fc and the winner’s result fb, or RaceTriple.Third with product of running tasks ƒa & fb and the winner’s result fc.
See Also
Do you like Arrow?
✖