:wave: In Kotlin, we have `MutableSharedFlow`. It ...
# coroutines
h
👋 In Kotlin, we have
MutableSharedFlow
. It contains a buffer. How does it work internally? Is an emitted value removed from the buffer if all subscribers read the value?
1
s
Not necessarily—some of the buffer can form the replay cache, which is kept indefinitely and replayed to new subscribers. The docs here should help: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/
h
Sorry, I oversimplified the question. The last emitted values are kept in the replay cache, but in the extra buffer, they are kept until all subscribers read them, right?
s
If there's no replay cache, a value in the buffer disappears once all subscribers have seen it, yes. (In that scenario, if there are no subscribers, values are dropped immediately and not buffered.) But if there's a replay cache, values in the extra buffer will eventually just make their way into that replay cache, as older values are consumed.
🙏 1
🔝 1
h
Thank you for the great explanation.
🐕 1
🍻 1