Last active: a year ago
use futures::future::join_all;
use tokio::sync::broadcast;
#[tokio::main]
async fn main() {
let (tx, mut rx1) = broadcast::channel(16);
let mut rx2 = tx.subscribe();
let mut handles = vec![];
let h1 = tokio::spawn(async move {
while let Ok(res) = rx1.recv().await {
dbg!(&res);
}
dbg!("done");
});
handles.push(h1);
let h1 = tokio::spawn(async move {
assert_eq!(rx2.recv().await.unwrap(), 10);
assert_eq!(rx2.recv().await.unwrap(), 20);
});
handles.push(h1);
tx.send(10).unwrap();
tx.send(20).unwrap();
drop(tx);
join_all(handles).await;
}