ratelimiter-rs

a lite ratelimit utils for rust

6 releases

0.1.5 Dec 17, 2023
0.1.4 Dec 17, 2023
0.1.3 Apr 17, 2023
Download history 12/week @ 2024-07-25 37/week @ 2024-08-01 11/week @ 2024-08-08 5/week @ 2024-08-15 1/week @ 2024-08-22 11/week @ 2024-08-29 10/week @ 2024-09-05 30/week @ 2024-09-12 33/week @ 2024-09-19 27/week @ 2024-09-26 33/week @ 2024-10-03 35/week @ 2024-10-10 19/week @ 2024-10-17 20/week @ 2024-10-24 25/week @ 2024-10-31 28/week @ 2024-11-07

93 downloads per month
Used in rnacos

MIT/Apache

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(),&times);
}

No runtime deps