6 releases
0.1.5 | Dec 17, 2023 |
---|---|
0.1.4 | Dec 17, 2023 |
0.1.3 | Apr 17, 2023 |
#1 in #ratelimit
107 downloads per month
Used in rnacos
11KB
277 lines
ratelimiter-rs
A lite ratelimit utils for rust.
examples
use std::thread;
use std::time::Duration;
use ratelimiter_rs::{QpsLimiter,RateLimiter,AtomicRateLimiter,now_millis};
fn qpslimiter(){
let mut limiter = QpsLimiter::new(10);
// AtomicRateLimiter can clone to other thread and use
//let limiter = AtomicRateLimiter::new(10);
let mut times = 0;
for _ in 0..3000 {
thread::sleep(Duration::from_millis(1));
if limiter.acquire() {
times +=1;
//println!("time: {}",now_millis())
}
else{
continue;
}
}
println!("time: {}, times: {}",now_millis(),×);
}