hi i have the following use case and i am sure i h...
# coroutines
t
hi i have the following use case and i am sure i have seen a flow implementation that supports it, however now i cannot find it 🤦‍♂️ i wish to execute a number of processes in parallel and consume the first one that completes and automatically cancel all remaining processes does Kotlin flow have such a function? or have i miss remembered and confused flow with LiveData?
j
I believe @louiscad wrote a library for exactly this use case in one of his Splitties module, but I don't believe this has been implemented in the coroutine library itself
Here is the module, you're looking for
raceOf
I believe: https://github.com/LouisCAD/Splitties/tree/main/modules/coroutines#racing-coroutines
You can find the issue tracking the (missing) feature in the coroutines library here: https://github.com/Kotlin/kotlinx.coroutines/issues/2867
t
cheers 😄
🙂 1
l
@Tower Guidev2 Did you perform searches on Google or another search engine while you were looking for a solution? If so, I'm curious what were your queries/keywords, I might write an extra article if needed (I already wrote one that you can find by Googling "racing coroutines").
t
@Lou i tried all sorts of combinations of "`kotlin flow parallel use first completed cancel remaining`" i am certain i have read official documentation for this exact function, maybe its implemented for android livedata the article i read concerned repository pattern and involved retreiving data from both the local database and remote network call and whichever one completed first provided the data for display while the "slower" call was cancelled gracefully ...maybe it was RxJava function that impleneted this 🤔
my searches were in google and duckduckgo
l
I think you mentioned the wrong handle @Tower Guidev2 If you can retrieve the history of the queries, I'd be very grateful that you send them to me via DM, I'll consider including the right keywords in a newer article with a different approach.
u
would merge.first() do what you want?