https://kotlinlang.org logo
#flow
Title
# flow
e

enighma

05/20/2020, 9:55 PM
Is there some nifty way to get the last emitted value of a flow, without having to cache it my self?
v

Vadim Ridosh

05/21/2020, 7:45 AM
Consider using StateFlow ?
I mean, if you look at Flow itself - it could be represented as an abstraction around a process of subscribing to event listener, getting some events (with possibity of generating side to inform that there won't be events anymore) and unsubscribe at any moment. If you want an ability to get the latest event - you can write your code that caches the event (that's what you propose) or include this ability to event sender's contract (StateFlow).
e

enighma

05/27/2020, 6:26 AM
I’ve not looked into StateFlow yet, but from what I’ve seen it might be what I’m after. Not sure it’s available in the kotlin version we’re currently are using, but I’m gonna have a look 🙂
a

adk

06/09/2020, 6:55 AM
fun <T> Flow<T>.conflate(): Flow<T>
might help.
2 Views