Hi guys :slightly_smiling_face: I just had a small...
# flow
j
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
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
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
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