# Async Throttle [github](https://github.com/wcygan/async-throttle) [crates.io](https://crates.io/crates/async-throttle) [docs.rs](https://docs.rs/async-throttle) [build status](https://github.com/wcygan/async-throttle/actions?query=branch%3Amain) [![codecov](https://codecov.io/github/wcygan/async-throttle/branch/main/graph/badge.svg?token=FW4Z2BUX1J)](https://codecov.io/github/wcygan/async-throttle) Asynchronous Rate Limiting This crate provides coarse and fine-grained ways to throttle the rate at which asynchronous tasks are executed. # Usage Add this to your Cargo.toml: ```toml [dependencies] async-throttle = "0.3.2" ``` You can use the fine-grained rate limiter like so: ```rust #[tokio::main] async fn main() { let period = std::time::Duration::from_secs(5); let rate_limiter = MultiRateLimiter::new(period); // This completes instantly rate_limiter.throttle("foo", || computation()).await; // This completes instantly rate_limiter.throttle("bar", || computation()).await; // This takes 5 seconds to complete because the key "foo" is rate limited rate_limiter.throttle("foo", || computation()).await; } ```