https://kotlinlang.org logo
#flow
Title
# flow
n

ninad thakare

06/14/2021, 2:20 PM
I want MutableSharedFlow to keep the values 1, 2 in it’s buffer if no one is collecting it.
g

gildor

06/14/2021, 3:14 PM
It will not work, you need channel for this SharedFlow allows only “repeat” behaviour, when you specify how many items will be sent to new subscriber
t

Todd

06/14/2021, 6:07 PM
Are you looking for replayCache?
g

gildor

06/14/2021, 7:05 PM
replayCache is the same as replay param in MutableSharedFlow
n

ninad thakare

06/14/2021, 8:30 PM
What I want is for it to accumulate the data till someone first subscribes. Not subsequent subscribes. So replay is out of the picture
g

gildor

06/15/2021, 1:35 AM
yep, this how channel with buffer works
n

ninad thakare

06/16/2021, 6:02 PM
Not how I want it to work. I want all the subsequent subscribers to get all the events
g

gildor

06/16/2021, 11:51 PM
If you need multicast, use BroadcastChannel
n

ninad thakare

06/17/2021, 2:42 PM
But then it doesn’t keep the buffer. I tried passing capacity = Channel.UNLIMITED. It crashes
2 Views