jonhoo / jonhoo/bus

Separate add_rx from Bus

Open
#24 14 comments 9 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
846
Forks
43
PR merge metrics
No merged PRs in 30d

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:

1. Send the `Bus` to a separate "dispatch" thread.
2. 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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the existing Bus and add_rx implementation, then inspect how Bus.state, Bus.leaving.0, Bus.waiting.0, and Bus.readers are used. Compare the proposal with issue #19 and review the benchmark coverage before deciding on the ReadHandle design. Done means receivers can be added or removed from the main thread after Bus moves to a dispatch thread, with synchronization behavior and benchmark effects addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.