https://github.com/darthbenro008/thread-broadcaster
A SPMC (Single Producer Multi Consumer) broadcasting channel to broadcast notifications between threads
https://github.com/darthbenro008/thread-broadcaster
channel concurrency mpmc rust spmc
Last synced: about 1 month ago
JSON representation
A SPMC (Single Producer Multi Consumer) broadcasting channel to broadcast notifications between threads
- Host: GitHub
- URL: https://github.com/darthbenro008/thread-broadcaster
- Owner: DarthBenro008
- License: mit
- Created: 2023-06-12T20:50:47.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-06-12T20:59:02.000Z (almost 2 years ago)
- Last Synced: 2024-04-23T20:55:05.898Z (about 1 year ago)
- Topics: channel, concurrency, mpmc, rust, spmc
- Language: Rust
- Homepage: https://docs.rs/thread-broadcaster/latest/thread_broadcaster/
- Size: 7.81 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# thread-broadcaster

[](https://github.com/DarthBenro008/thread-broadcaster/blob/master/LICENSE)
[](
https://docs.rs/thread-broadcaster)Thread Broadcaster is a Single Channel Multi-Producer (SPMC) library that enables the sending of notifications between threads. Unlike most Multi-Producer Multi-Consumer (MPMC) implementations, Thread Broadcaster ensures that all listeners receive the data, rather than just the first one.
## 🤔 Features
- Single Channel Multi-Producer (SPMC) architecture
- Tad bit faster than MPMC (thanks to [crossbeam-channel](https://crates.io/crates/crossbeam-channel)!)
- Senders and Receivers can be cloned and shared among threads.
- Simple and intuitive API for sending and receiving notifications
- Asynchronous notification broadcasting between threads
- Support `tracing` for debugs## ⚡️ Quickstart
```rust
use core::time;
use std::thread;use thread_broadcaster::{BroadcastListener, Broadcaster};
fn main() {
let (b, s) = Broadcaster::::new();
let s2 = s.clone();
thread::spawn(move || {
let ls1 = BroadcastListener::register_broadcast_listener(s);
for msg in ls1.channel {
println!(
"got broadcast with data: {} on thread {:#?}",
msg,
thread::current().id()
);
}
});
thread::spawn(move || {
let ls2 = BroadcastListener::register_broadcast_listener(s2);
for msg in ls2.channel {
println!(
"got broadcast with data: {} on thread {:#?}",
msg,
thread::current().id()
);
}
});
thread::spawn(move || {
// we wait for registration
thread::sleep(time::Duration::from_secs(1));
b.broadcast("something to broadcast".to_string());
// we wait for listeners to pickup before being dropped
thread::sleep(time::Duration::from_secs(2));
})
.join()
.unwrap();
}
```## ⬇️ Installation
```
cargo add thread-broadcaster
```
## 🤝 Contributions- Feel Free to Open a PR/Issue for any feature or bug(s).
- Make sure you follow the [community guidelines](https://docs.github.com/en/github/site-policy/github-community-guidelines).
- Feel free to open an issue to ask a question/discuss anything about melonpan.
- Have a feature request? Open an Issue!## ⚖ License
Copyright 2022 Hemanth Krishna
Licensed under MIT License : https://opensource.org/licenses/MIT
Made with ❤ and multiple cups of coffee