darkmoon_uk
04/07/2021, 8:35 AMFlow
setup) forms a circular reference.
In these cases, it's impossible to declare all parts of an overall Flow linearly; at some point we need to reference a part that hasn't been declared yet.
In RxJava the idiomatic way to work around this was using Relay
- a specialised Subject
.
Is there a Flow
equivalent?
It seems that a MutableSharedFlow
with replay = 0
will have the right semantics.elizarov
04/07/2021, 8:39 AMSharedFlow
is designed for multiple subscribers and loses items when there are no subscriptions. If you need guaranteed delivery and expect that a single subscriber comes at a later point in time, then Channel
is a better solution.darkmoon_uk
04/07/2021, 8:43 AMChannel
can be a better choice; guaranteed delivery and no sharing mechanism which may be extraneous if we're looking to merely join a 'loop' (at least with consumeAsFlow()
).