3 releases

0.3.2 Mar 31, 2023
0.3.1 Mar 30, 2023
0.3.0 Mar 28, 2023
0.2.0 Aug 30, 2020
0.1.0 Jun 2, 2020

#2253 in Asynchronous

Download history 6974/week @ 2025-07-18 5890/week @ 2025-07-25 3623/week @ 2025-08-01 4183/week @ 2025-08-08 6154/week @ 2025-08-15 7436/week @ 2025-08-22 5618/week @ 2025-08-29 6605/week @ 2025-09-05 6980/week @ 2025-09-12 7299/week @ 2025-09-19 5554/week @ 2025-09-26 4973/week @ 2025-10-03 4266/week @ 2025-10-10 5185/week @ 2025-10-17 5057/week @ 2025-10-24 3868/week @ 2025-10-31

18,995 downloads per month
Used in 3 crates (via tokio-utils)

MIT license

18KB
277 lines

Async Throttle

github crates.io docs.rs build status codecov

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:

[dependencies]
async-throttle = "0.3.2"

You can use the fine-grained rate limiter like so:

#[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;
}

Dependencies

~3.5–6.5MB
~108K SLoC