async_limiter 0.1.3

Simple ratelimiter for async tasks.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented1 out of 1 items with examples
  • Size
  • Source code size: 5.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.53 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • BerserkerMother/async_limiter
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • BerserkerMother

async_limiter

Crates.io Documentation License

An asynchronous rate limiter for Rust based on the token bucket algorithm.

Installation

Add this to your Cargo.toml:

[dependencies]
async_limiter = "0.1"

Basic Usage

let limiter = RateLimiter::new(1000, Duration::from_secs(47));
for _ in 0..10000 {
    let limiter = limiter.clone();
    tokio::spawn(async move {
        limiter.wait().await;
        let body = reqwest::get("https://rickandmortyapi.com/api/episode/16")
            .await
            .unwrap()
            .text()
            .await
            .unwrap();
    });
}

Contribution

I developed this simple package for my own use cases. I thought it may benefit others. If I missed something or you need a new feature, feel free to open an issue.