This week, my version of how to race coroutines in...
# feed
s
This week, my version of how to race coroutines in Kotlin. I think the ability to customize the race with operators like
filter()
makes
channelFlow()
an amazing solution for this. https://medium.com/@sam-cooper/custom-kotlin-coroutine-races-77161141b2ac
🔥 2
The first place I saw this technique was in this comment from Louis Wasserman—does anyone know if it's been used in the wild before that?
a
you may already be aware of this, but the Arrow library provides race operations out of the box https://arrow-kt.io/learn/coroutines/parallel/#racing
🙌 1
s
Yeah, I think I have used the Arrow
raceN
function before 👍. Can it express something like
raceNotNull
, though? That extra customizability is the reason I really love the
channelFlow
method.
I'll add the mention of Arrow to my article either way, that's a good call
thank you color 1
a
Can it express something like
raceNotNull
, though?
no, but you have given me an idea for a new function 😄
arrow intensifies 4
🙌 1
s
😄 maybe you can implement it with a
channelFlow
😉