gardal 0.0.1-alpha.1

A WIP performance-focused token-bucket rate limiting and throttling library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::time::Duration;

use gardal::{RateLimit, RawTokenBucket};
use nonzero_ext::nonzero;

fn main() {
    let tb = RawTokenBucket::new(RateLimit::per_second_and_burst(
        nonzero!(10u32),
        nonzero!(20u32),
    ));
    // after two seconds bucket should be full
    std::thread::sleep(Duration::from_secs(2));
    assert_eq!(5, tb.consume(nonzero!(5u32)).unwrap().as_u64());
}