use arl::RateLimiter;
use std::sync::{Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
#[tokio::main]
async fn main() {
let limiter = RateLimiter::new(10, Duration::from_secs(2));
let counter = Arc::new(Mutex::new(0));
for i in 0..4 {
let limiter = limiter.clone();
let counter = counter.clone();
tokio::spawn(async move {
loop {
limiter.wait().await;
let mut c = counter.lock().unwrap();
*c += 1;
println!("Counter: {} by thread #{}", c, i);
}
});
}
sleep(Duration::from_secs(21));
}