You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
814 B
29 lines
814 B
use tokio::sync::broadcast; |
|
|
|
#[tokio::main(flavor = "current_thread")] |
|
async fn main() { |
|
let (tx, _) = broadcast::channel(1); |
|
|
|
for i in 0..30000 { |
|
let mut rx = tx.subscribe(); |
|
let _consumer = tokio::spawn(async move { |
|
while let Ok(mess) = rx.recv().await { |
|
println!("Consumer {}: {}", i, mess); |
|
} |
|
println!("Consumer {} is done", i); |
|
}); |
|
} |
|
|
|
let producer = tokio::spawn(async move { |
|
// let mut rng = 3; |
|
loop { |
|
tx.send(42).expect("Failed to send!"); |
|
tokio::task::yield_now().await; |
|
// rng += 17 % 200; |
|
// let duration = tokio::time::Duration::from_millis(rng); |
|
// tokio::time::sleep(duration).await; |
|
} |
|
}); |
|
|
|
let _ = producer.await; |
|
}
|
|
|