-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Receiver is not multi-consumer #57
Comments
No, it does not. You can clone the receiver as many times as you need and give it out to threads/tasks. Unlike, async-channel, each receiver gets a clone of each message sent to the channel. I'm using async-broadcast in my own project and it wouldn't be very useful for me (or perhaps anyone) if it had such a limitation.
At the moment, no but that's due to the current implementation using interior mutability. The reason I kept the original API (I took over someone's project) was that I thought if we had to the change the implementation for any reason, turning the reference into a mutable one will be a breaking change and a pretty inconvenient one. However, it's now been years and the implementation has proven to be quite solid by now. Perhaps we can change it now. @notgull any thoughts?
I don't think this difference is relevant. What users need to know is where they'll use -channel and where they'll use -broadcast and I think that's covered already. |
I think it needs to be Line 788 in 74d5889
...similar to how It would be possible to rewrite the implementation to use |
In my case I don't really need multiple consumers on a single receiver: deltachat/deltachat-core-rust#5478 I am pretty sure mutex is never locked by multiple threads unless someone uses API in unintended way, e.g. issuing multiple calls to So it is not a blocker for my use case, but makes |
Ah right. Should have looked more carefully. Thanks. :)
Yeah, me neither. If we can use interior mutability, so can the user and it allows users who don't need interior mutability a a choice and avoid locking costs etc.
It's not supposed to be a "drop-in" replacement really. I know it would be very convenient if it was but see what I wrote above. |
README describes
async-broadcast
as an MPMC channel similar toasync-channel
:async-broadcast/README.md
Line 65 in 74d5889
However, in case of
async-broadcast
Receiver.recv()
,Receiver.recv_direct()
andReceiver.try_recv()
take&mut self
instead of&self
. This means it is impossible to have multiple threads taking messages from a singleReceiver
side, e.g. to distribute some kind of work between threads. Naive solution of wrappingReceiver
into async mutex does not work because any thread holding the mutex while callingrecv()
will also block any thread callingtry_recv()
sotry_recv()
will not return immediately as it should. Having multipleReceiver
s also does not make the channel multi-consumer, in a way creating a receiver creates a new "channel" with its own buffer that is subscribed to the same broadcast sender.Is there technical limitation that prevents making receiving calls take non-
mut
reference&self
? If it is not possible to change e.g. for performance reasons, I think at least the documentation should be corrected to describe whyasync-broadcast
differs fromasync-channel
in this aspect.The text was updated successfully, but these errors were encountered: