tokio-based leaky-bucket rate limiter
This project is a rate limiter based on the leaky bucket algorithm.
Usage
This library requires the user to add the following dependencies to use:
= "0.5.0"
Examples
use LeakyBuckets;
use ;
async
This project is a rate limiter based on the leaky bucket algorithm.
This library requires the user to add the following dependencies to use:
leaky-bucket = "0.5.0"
use leaky_bucket::LeakyBuckets;
use std::{error::Error, time::Duration};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let rate_limiter = LeakyBucket::builder()
.max(100)
.refill_interval(Duration::from_secs(10))
.refill_amount(100)
.build()?;
println!("Waiting for permit...");
// should take about ten seconds to get a permit.
rate_limiter.acquire(100).await?;
println!("I made it!");
Ok(())
}