rate_limiter_test/
rate_limiter_test.rs

1use std::{thread::sleep, time::Duration};
2
3use amazon_spapi::client::rate_limiter;
4use anyhow::Result;
5
6#[tokio::main]
7async fn main() -> Result<()> {
8    env_logger::init();
9
10    let rate_limiter = rate_limiter::RateLimiter::new();
11
12    for i in 1..=5 {
13        let _ = rate_limiter.wait("func1", 1.0, 15).await?;
14        println!("call {}, time: {}", i, chrono::Local::now());
15    }
16
17    sleep(Duration::from_secs(5));
18
19    for i in 1..=20 {
20        let _ = rate_limiter.wait("func1", 1.0, 15).await?;
21        println!("call {}, time: {}", i, chrono::Local::now());
22    }
23
24    sleep(Duration::from_secs(15));
25
26
27    for i in 1..=20 {
28        let _ = rate_limiter.wait("func1", 1.0, 15).await?;
29        println!("call {}, time: {}", i, chrono::Local::now());
30    }
31
32    Ok(())
33}