1use future_bool::FutureBool;
2
3macro_rules! sleep {
4 ($sec:expr) => {
5 ::tokio::time::sleep(::tokio::time::Duration::from_secs($sec)).await
6 };
7}
8
9#[tokio::main]
10async fn main() {
11 let b: FutureBool = FutureBool::new(false);
12 let mut tasks = Vec::new();
13
14 for x in 0..20 {
15 let clone = b.clone();
16 if x % 2 == 0 {
17 tasks.push(tokio::spawn(async move {
18 clone.wait_true().await;
19 eprintln!("{:2}: Yess", x);
20 }));
21 } else {
22 tasks.push(tokio::spawn(async move {
23 clone.wait_false().await;
24 eprintln!("{:2}: Nope", x);
25 }));
26 }
27 }
28
29 sleep!(2);
30 b.set();
31
32 for task in tasks {
33 let _ = task.await;
34 }
35}