jonhoo / jonhoo/bus

Using a 0 sized buffer causes broadcasts to never be received

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

Description

When a bus is created with a buffer of 0, messages are successfully broadcast, but are never received. I'm not sure if you care about such a use case (I want to receive only messages being sent now, not messages that may have been sitting in the queue waiting for a reader), but if not it woudl be good to get a message/panic when creating such a bus. Code:

```
extern crate bus;

use bus::Bus;
use std::thread;
use std::time::Duration;
fn main() {
let mut bus = Bus::new(0);
let mut rx = bus.add_rx();
let t = thread::spawn(move || {
rx.recv().unwrap();
});
thread::sleep(Duration::from_millis(500));
println!("Sending");
bus.broadcast(());
println!("Sent, waiting on receive");
t.join().unwrap();
println!("Received and joined");
}
```

In this minimal example, the sent message is always printed, but the final received/joined message is not. Increasing the buffer to 1 makes it complete successfully.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.