Jan Skrasek07/30/2021, 10:10 PM
with runBlockingTest I would expect both to behave the same; Yet when not using extraBufferaCapacity = 1, my following test fails for MutableSharedFlow and not for Channel. (See gist) https://gist.github.com/hrach/94ba0dc427ad2f08a73467d8972516a2 • why is there a difference? • is both behavior correct? • is correct that there is a difference?
Nick Allen07/30/2021, 11:55 PM
with no buffer space and
will always fail and return false.
. It can send events to many listeners, but it is not a queue.
Jan Skrasek07/31/2021, 5:52 AM
You are setting up yourwith no buffer space and
SUSPENDwill always fail and return false.
This seems to be crucial info. It could be in kdoc. Still I don't understand why channel with no buffer is able to handle this.
Nick Allen07/31/2021, 6:19 PM
uses a callback mechanism. When you call
you wait for
to finish. If
isn't allowed to store the value in a buffer, its
needs to loop through the listeners and wait for
to finish for each listener.
waits for the data to be received, it does not wait for the data to be processed at all. It's more of a hand-off.
doesn't need to suspend just to tell another coroutine to resume.
works because that's how it's designed to work.
could maybe work if its implementation changed, idk. Right now it just checks the buffer and buffer strategy to determine if tryEmit can work without suspending. This is nice because it's simple and fast. It could conceivably check if all listeners are "ready" but I imagine that could cause performance or just complexity issues. I wouldn't say it's super clear, but the behavior does feel like it's documented in the kdocs here: "When this function returns
, it means that the call to a plain emit function will suspend until there is a buffer space available."
Jan Skrasek07/31/2021, 9:21 PM