phlow_sdk/
count.rs

1pub struct Count {
2    count: u64,
3}
4
5impl Count {
6    pub fn new() -> Self {
7        Count { count: 0 }
8    }
9
10    pub fn add(&mut self) {
11        self.count += 1;
12    }
13
14    pub fn sub(&mut self) {
15        self.count -= 1;
16    }
17
18    pub fn get(&self) -> u64 {
19        self.count
20    }
21}
22
23#[macro_export]
24macro_rules! counter_listener {
25    ($counter:expr, $time:expr) => {
26        let counter_clone = counter.clone();
27        tokio::task::spawn(async move {
28            loop {
29                tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
30                let count = counter_clone.lock().unwrap().get();
31                println!("Current count: {}", count);
32            }
33        });
34    };
35}