{"id":18427052,"url":"https://github.com/mindeng/async-rate-limiter","last_synced_at":"2025-08-14T21:08:51.506Z","repository":{"id":253436877,"uuid":"843504429","full_name":"mindeng/async-rate-limiter","owner":"mindeng","description":"Implements a token bucket algorithm that can be used to limit API access frequency. Written in pure Rust.","archived":false,"fork":false,"pushed_at":"2024-08-22T23:09:19.000Z","size":73,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-31T11:59:01.958Z","etag":null,"topics":["crate","frequency-control","rate-limit","rate-limiter","rate-limiting","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mindeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-16T16:58:32.000Z","updated_at":"2024-08-22T23:09:22.000Z","dependencies_parsed_at":"2024-08-23T00:05:38.139Z","dependency_job_id":null,"html_url":"https://github.com/mindeng/async-rate-limiter","commit_stats":null,"previous_names":["mindeng/async-rate-limiter","mindeng/rate-limiter-rs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindeng%2Fasync-rate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindeng%2Fasync-rate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindeng%2Fasync-rate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindeng%2Fasync-rate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mindeng","download_url":"https://codeload.github.com/mindeng/async-rate-limiter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223286385,"owners_count":17120000,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crate","frequency-control","rate-limit","rate-limiter","rate-limiting","rust"],"created_at":"2024-11-06T05:09:32.555Z","updated_at":"2024-11-06T05:09:33.072Z","avatar_url":"https://github.com/mindeng.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-rate-limiter\n\n[![crates.io](https://img.shields.io/crates/v/async-rate-limiter.svg)](https://crates.io/crates/async-rate-limiter)\n[![Documentation](https://docs.rs/async-rate-limiter/badge.svg)](https://docs.rs/async-rate-limiter)\n[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![CI](https://github.com/mindeng/async-rate-limiter/actions/workflows/rust.yml/badge.svg)](https://github.com/mindeng/async-rate-limiter/actions)\n\nasync-rate-limiter implements a [token bucket\nalgorithm](https://en.wikipedia.org/wiki/Token_bucket) that can be used to\nlimit API access frequency.\n\n## Features\n\n- Simple to use\n- Support concurrent access\n- Low overhead, the number of tokens is calculated over time\n\nThanks to Rust’s `async` / `await`, this crate is very simple to use. Just put\nyour function call after\n[`RateLimiter::acquire()`](https://docs.rs/async-rate-limiter/latest/async_rate_limiter/struct.RateLimiter.html#method.acquire).`await`,\nthen the function will be called with the specified rate limit.\n\n[`RateLimiter`] also implements `Clone` trait, so you can use it in\nmultiple tasks environment easily.\n\n## Example\n\nUpdate your `Cargo.toml`:\n\n```toml\n[dependencies]\n# Change features to [\"rt-async-std\"] if you are using async-std runtime.\nasync-rate-limiter = { version = \"1\", features = [\"rt-tokio\"] }\n```\n\nHere is a simple example:\n\n```rust\nuse async_rate_limiter::RateLimiter;\nuse std::time::Duration;\nuse tokio::spawn;\n\n#[tokio::main]\nasync fn main() {\n    let rl = RateLimiter::new(3);\n    // You can change `burst` at anytime\n    rl.burst(5);\n    \n    rl.acquire().await;\n    println!(\"Do something that you want to limit the rate ...\");\n\n    let res = rl.try_acquire();\n    if res.is_ok() {\n        println!(\"Do something that you want to limit the rate ...\");\n    }\n\n    // acquire with a timeout\n    let ok = rl.acquire_with_timeout(Duration::from_secs(10)).await;\n    if ok {\n        println!(\"Do something that you want to limit the rate ...\");\n    }\n\n    // Concurrent use\n    let rl = rl.clone();\n    spawn(async move {\n        let res = rl.acquire_with_timeout(Duration::from_millis(340)).await;\n        assert!(res);\n    });\n}\n\n```\n\nasync-rate-limiter can support different async runtimes, tokio \u0026 async-std\nare supported currently. You can use features to switch async runtimes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindeng%2Fasync-rate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmindeng%2Fasync-rate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindeng%2Fasync-rate-limiter/lists"}