async_throttle/lib.rs
1//! Tools for rate limiting asynchronously
2//!
3//! * [`MultiRateLimiter`], a key-based rate limiter
4//! * [`RateLimiter`], a rate limiter
5//!
6//! # Examples
7//!
8//! ```
9//! use async_throttle::MultiRateLimiter;
10//! use std::sync::Arc;
11//!
12//! #[tokio::main]
13//! async fn main() {
14//! let period = std::time::Duration::from_secs(5);
15//! let rate_limiter = MultiRateLimiter::new(period);
16//!
17//! // This completes instantly
18//! rate_limiter.throttle("foo", || computation()).await;
19//!
20//! // This completes instantly
21//! rate_limiter.throttle("bar", || computation()).await;
22//!
23//! // This takes 5 seconds to complete because the key "foo" is rate limited
24//! rate_limiter.throttle("foo", || computation()).await;
25//! }
26//!
27//! async fn computation() { }
28//! ```
29pub use multi::MultiRateLimiter;
30pub use single::RateLimiter;
31mod multi;
32mod single;