Erik
05/03/2021, 1:50 PMMutableSharedFlow()
by default has no buffer (replay = 0
, extraBufferCapacity = 0
, i.e. buffer = replay + extraBufferCapacity = 0
). Does that mean that if I have many emitters that call emit
, that they would suspend (in order) until the subscribers of the shared flow process the emissions one by one? So, in other words: has the buffer moved away from the shared flow, that intrinsically has no buffer space, to the coroutine scope(s) that now contain various suspended child coroutines trying to emit
?Tijl
05/03/2021, 2:00 PMUnbuffered shared flow
)Erik
05/03/2021, 2:07 PMTijl
05/03/2021, 2:09 PMBufferOverflow.SUSPEND
will behave the same way (once the buffer is full)Erik
05/03/2021, 2:14 PMtryEmit
another value, does it return false
because not all subscribers were ready for a new value, yet?Tijl
05/03/2021, 2:16 PMtryEmit
will always fail if you have no buffer to put it in (which you never have since it’s size 0
), unless there are no subscribers at all (this is a documented behaviour in the link I gave)Erik
05/03/2021, 2:18 PMtryEmit
faster than values are collected?tryEmit
must fail, I would guessTijl
05/03/2021, 2:18 PMErik
05/03/2021, 2:19 PMTijl
05/03/2021, 2:20 PMBufferOverflow.SUSPEND
emits
will always arrive but tryEmit
only if the buffer is emptied in timeErik
05/03/2021, 2:25 PMMutableSharedFlow()
factory function has no buffer. It promotes using coroutines on the producing side.tryEmit
and some buffer come in handy.MutableSharedFlow(...)
with arguments can look a bit verbose.Tijl
05/03/2021, 2:39 PMMutableStateFlow
) with a buffer size of 1 (and dropping), which essentially replaces ConflatedBroadcastChannel
I personally agree with the decision however, default buffer sizes confuse people, things will work during development and fail during production when the buffer is suddenly full, better make them specify it explicitly so they are aware there is a buffer of a certain size.Erik
05/03/2021, 2:53 PMemit
is called? Do emit
calls suspend until successfully emitting the values, or do they return quickly and lose the value?Tijl
05/03/2021, 2:55 PMErik
05/03/2021, 2:59 PMTijl
05/03/2021, 2:59 PMErik
05/03/2021, 3:06 PMFrancesc
05/03/2021, 3:37 PMemit
).Tijl
05/03/2021, 3:39 PMI think what you might be getting at is “does this mean none of my emits will be dropped” and the answer is “yes” (as long as there are subscribers)and that’s no accident of course 🙂
Erik
05/03/2021, 3:52 PMemit
calls, there is backpressure without blocking (unless the coroutine context that suspends is blocking, of course).emit
depends on the buffer size, the buffer overflow strategy and the presence of subscribers. Especially the last one is a bit surprising, but I might find a good reason in the design documentation.Tijl
05/03/2021, 4:02 PMErik
05/03/2021, 4:09 PM