Some points about using SharedFlow for dispatching single events:
- Events are lost when there are no subscribers
- Multiple subscribers will all receive the same event
a
Andrea Nicoletti
11/16/2020, 8:26 AM
Like the others said, you can use a SharedFlow with replay = 0 so that the new value will be emitted only once and not repeated
m
Michael Ferguson
11/17/2020, 2:19 PM
I don’t like using SharedFlow on Android to handle “events”. I like to use a channel with
receiveAsFlow
so that on configuration change if an event is emitted with no observers it’s not dropped. (The channel buffers while there are no observers while SharedFlow is hot.) There are some caveats when doing that though.
https://medium.com/@elizarov/shared-flows-broadcast-channels-899b675e805c
Has a really good explanation of that “single shot event” use case.