async-rate-limiter
async-rate-limiter implements a token bucket algorithm that can be used to limit API access frequency.
Features
- Simple to use
- Support concurrent access
- Low overhead, the number of tokens is calculated over time
Thanks to Rust’s async / await, this crate is very simple to use. Just put
your function call after
RateLimiter::acquire().await,
then the function will be called with the specified rate limit.
[RateLimiter] also implements Clone trait, so you can use it in
multiple tasks environment easily.
Example
Update your Cargo.toml:
[]
# Change features to ["rt-async-std"] if you are using async-std runtime.
= { = "1", = ["rt-tokio"] }
Here is a simple example:
use RateLimiter;
use Duration;
use spawn;
async
async-rate-limiter can support different async runtimes, tokio & async-std are supported currently. You can use features to switch async runtimes.