ratelimit-rs
This package provides a simple Rust implementation of uber-go/ratelimit(https://github.com/uber-go/ratelimit) -- a rate limiter based on leaky-bucket algorithm.
AtomicLimiter is a implmentation of trait Limiter
as a sample in the package, you can use it the same way as it in uber-go/ratelimit.
use chrono::{Duration, Utc};
use ratelimit_rs::AtomicLimiter;
fn main() {
let mut limiter = AtomicLimiter::new(100);
let mut prev = Utc::now().timestamp_millis();
for i in 0..10 {
let now = limiter.take();
println!("{} {}ms", i, now - prev);
prev = now;
}
// 0 0ms
// 1 10ms
// 2 10ms
// 3 10ms
// 4 10ms
// 5 10ms
// 6 10ms
// 7 10ms
// 8 10ms
// 9 10ms
}