Hello everyone! Would : ``` private val _event = ...
# coroutines
m
Hello everyone! Would :
Copy code
private val _event = MutableSharedFlow<S>(extraBufferCapacity = 1)
    val event: SharedFlow<S> get() = _event.asSharedFlow()
be a correct alternative to
Channels
for single shots events? Or would events would still be dropped if there are no subscribers
s
In my experience, without subscribers, calling
emit
will cause the event to be dropped.
This would make it wait for at least
n
subscribers:
Copy code
subscriptionCount.first { it >= n }
emit(value)
m
This suggest of using Channels, which I know is a valid alternative, my question was if the snippet I shared could work as a replacement for Channels
j
In that post you can see a section about SharedFlow
m
Copy code
What about the use of SharedFlow? Can that help? Unfortunately, no. SharedFlow is hot. This means that during periods where the is no observer, say during a configuration change, events emitted on to the flow are simply dropped. Regrettably, this also makes SharedFlow inappropriate to emit events on.
You mean this?
👌 1