ratelimiter-rs

Crates.ioratelimiter-rs
lib.rsratelimiter-rs
version0.1.5
sourcesrc
created_at2023-04-14 12:04:49.705452
updated_at2023-12-17 16:32:07.968015
descriptiona lite ratelimit utils for rust
homepage
repositoryhttps://github.com/heqingpan/ratelimiter-rs
max_upload_size
id839114
size12,836
heqingpan (heqingpan)

documentation

README

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);
}
Commit count: 9

cargo fmt