`BroadcastChannel` drops items if there are no sub...
# coroutines
a
BroadcastChannel
drops items if there are no subscribers. Is there a way to not drop but buffer? Looking for something with
UnicastSubject
behaviour.
g
I think you just need to pass a positive
capacity
value to the BroadcastChannel factory function https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel.html
a
Nope, this is stated in docs: "Note: this channel looses all items that are send to it until the first subscriber appears;"
g
I can’t find that, do you remember where? AFAIK, BroadcastChannel doesn’t impose that limitation
a
Just open the link you provided 🙂
message has been deleted
😅 1
g
Sounds like you need a cold stream, actually. How about a buffered Flow?
a
From my point of view Flow will not buffer anything unless subscribed. Isn't it?
I’m not sure
g
Yes, Flow is cold, will not buffer before start subscribing on it. You can just open subscription on this channel and do not consume elements, so it will start buffering
a
Thanks, will give it a try.