https://kotlinlang.org logo
#coroutines
Title
# coroutines
g

Gilles Barbier

02/05/2021, 7:56 PM
Hi, I'm using a
MutableSharedFlow
with a collect lambda.
Copy code
val responseFlow = MutableSharedFlow<Message>(replay = 0)
...
responseFlow.collect {
...
}
When I collect a message, I do a test and for some value , I would like to leave the collect function and return a value. I'm not sure how to do that. Any idea?
w

wasyl

02/05/2021, 8:00 PM
Do you only care about that specific value? You can do
flow.first { condition }
for example
g

Gilles Barbier

02/05/2021, 8:01 PM
Oh! I did not know. Let me try that
It works, I'm a bit ashamed by such a simple solution... thank you !
👍 1
4 Views