tokio-based leaky-bucket rate limiter

Build Status

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:

toml leaky-bucket = "0.1.0"

Examples

```rust

![feature(async_await)]

use futures::prelude::*; use leaky_bucket::LeakyBucket; use std::{error::Error, time::Duration};

[tokio::main]

async fn main() -> Result<(), Box> { let ratelimiter = LeakyBucket::builder() .max(100) .refillinterval(Duration::fromsecs(10)) .refillamount(100) .build();

let coordinator = rate_limiter.coordinate().boxed();

// spawn the coordinate thread to refill the rate limiter.
tokio::spawn(async move { coordinator.await.expect("coordinate thread errored") });

println!("Waiting for permit...");
// should take about ten seconds to get a permit.
rate_limiter.acquire(100).await;
println!("I made it!");

Ok(())

} ```