Crate ratelimiter [] [src]

Rate limiter for rust. Acquire tokens as futures which are resolved when the token is ready.

Example Acquiring a Token

extern crate ratelimiter;
extern crate futures;
use ratelimiter::{RateLimiter, TokenFuture};
use futures::executor::ThreadPool;
use std::time::Duration;

use futures::FutureExt;
let mut rate_limiter = RateLimiter::new(1, 1, Duration::from_secs(1));
let token: TokenFuture = rate_limiter.acquire_token();
let and_then = token.and_then(|_| {
    println!("Token acquired!");
    return Ok(());
});
ThreadPool::new().unwrap().run(and_then);

Structs

RateLimiter

Limits the rate at which things can happen.

TokenFuture

Future for a single token