2 unstable releases
0.2.3 | Jun 21, 2022 |
---|---|
0.2.2 |
|
0.2.1 |
|
0.2.0 |
|
0.1.0 | Sep 13, 2020 |
#1884 in Asynchronous
630 downloads per month
17KB
318 lines
barrage
A simple async broadcast channel. It is runtime agnostic and can be used from any executor. It can also operate synchronously.
Example
#[tokio::main]
async fn main() {
let (tx, rx) = barrage::unbounded();
let rx2 = rx.clone();
tx.send_async("Hello!").await.unwrap();
assert_eq!(rx.recv_async().await, Ok("Hello!"));
assert_eq!(rx2.recv_async().await, Ok("Hello!"));
}
lib.rs
:
Barrage - an asynchronous broadcast channel. Each message sent will be received by every receiver. When the channel reaches its cap, send operations will block, wait, or fail (depending on which type of send was chosen). Cloned receivers will only receive messages sent after they are cloned.
Example
let (tx, rx1) = barrage::unbounded();
let rx2 = rx1.clone();
tx.send("Hello!");
let rx3 = rx1.clone();
assert_eq!(rx1.recv(), Ok("Hello!"));
assert_eq!(rx2.recv(), Ok("Hello!"));
assert_eq!(rx3.try_recv(), Ok(None));
Dependencies
~355KB