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

Jérémy CROS

07/05/2021, 1:50 PM
Hi guys 🙂 I just had a small argument with myself regarding how to expose a flow in an interface. The implementation is backed by a shared flow. Obviously, no
MutableSharedFlow
exposed. But would you have a
SharedFlow
exposed? Since the consumer may need to know that it’s hot? Or a regular
Flow
? Since the consumer is just going to ‘.collect()’ anyway? Or is it a case by case discussion?
g

gildor

07/06/2021, 3:04 AM
I prefer always expose the most abstract type, so it would be Flow
It makes sense to expose SharedFlow only if for some reason consumer uses replayCache, but It very unlikely
And I don’t think that it should be any indicator of Hot flow for sake of indicator, it should be transparent for consumer when it’s possible
j

Jérémy CROS

07/06/2021, 7:15 AM
First of all, thanks for the quick reply 🙂 So yeah, the question is indeed related to replay cache. My first instinct was to also expose to most abstract type ie Flow and that’s how the interface was designed in the first place. Right now, we could either change to SharedFlow, update a trillion tests or keep it like that and right a small workaround for when we need to store a “current” value Anyway, thanks again, I think it has helped me clear my thoughts 🙂
g

gildor

07/06/2021, 7:21 AM
I really don’t see reason to expose SharedFlow, because it’s a bit pointless for consumer, replayCache can be empty or if there is no items to reply or if SharedFlow was configured with replyCache=0 So I don’t see valid use cases for exposing SharedFlow in public API
👍 3
🙏 2
2 Views