-
Notifications
You must be signed in to change notification settings - Fork 41
Description
This might be related to or a duplicate of #19 , but it's not clear based on the wording of the original issue.
The problem with add_rx being tied to Bus occurs in my use case where I want to:
- Send the
Busto a separate "dispatch" thread. - Dynamically add/remove receivers over time on the main thread.
Once the Bus has been moved to the dispatch thread, it can't be used on the main thread to create more receivers, thus fixing the number that I can create. It is technically possible to send messages to create more and send them back via channels, but I have another idea I'd like to pursue to see if it's any better.
What I propose is creating a secondary interface (let's call it ReadHandle for now), which could be created by a method on Bus and would also implement add_rx.
Internally, it would only involve taking clones of Bus.state and the senders Bus.leaving.0, Bus.waiting.0 when constructed, so it would be mostly zero-cost. The one major change would be making Bus.readers atomic and moving it to BusInner, but we can at least try it and see how it affects benchmarks.