{"id":15692363,"url":"https://github.com/deknowny/raliguard","last_synced_at":"2025-06-18T03:02:47.891Z","repository":{"id":39647554,"uuid":"493794951","full_name":"deknowny/raliguard","owner":"deknowny","description":"Lazy rate limit semaphore (a.k.a fixed window algorithm without queueing) implementation to control your asynchronous code frequency execution","archived":false,"fork":false,"pushed_at":"2023-06-21T01:15:24.000Z","size":62,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T23:41:34.859Z","etag":null,"topics":["async","rate-limiter","rate-limiting","rust","rust-lang","semaphore","threads","tokio","tokio-rs"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deknowny.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":"2022-05-18T19:12:57.000Z","updated_at":"2024-10-21T17:36:14.000Z","dependencies_parsed_at":"2024-10-24T00:13:40.120Z","dependency_job_id":"4fa59300-f247-492c-9169-38242fcd36a8","html_url":"https://github.com/deknowny/raliguard","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.032258064516129004","last_synced_commit":"798aa502291bec3015cd496276b9bee46c24cdd6"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/deknowny/raliguard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deknowny%2Fraliguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deknowny%2Fraliguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deknowny%2Fraliguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deknowny%2Fraliguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deknowny","download_url":"https://codeload.github.com/deknowny/raliguard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deknowny%2Fraliguard/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259813336,"owners_count":22915215,"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":["async","rate-limiter","rate-limiting","rust","rust-lang","semaphore","threads","tokio","tokio-rs"],"created_at":"2024-10-03T18:32:06.000Z","updated_at":"2025-06-18T03:02:42.861Z","avatar_url":"https://github.com/deknowny.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rate limit guard\nLazy rate limit semaphore (a.k.a fixed window algorithm without queueing) implementation to control your asynchronous code frequency execution\n\n***\n__Documentation__: [lib.rs/raliguard](lib.rs/raliguard)\n\n## Overview\n```rust\nuse std::{thread, sync, time};\n\nuse raliguard::Semaphore;\n\n\n// Create a semaphore with restriction `5 tasks per 1 second`\nlet originl_sem = Semaphore::new(5, time::Duration::from_secs(1));\n\n// Make it sharable between treads (or you can share between tasks)\nlet shared_sem = sync::Arc::new(\n    sync::Mutex::new(originl_sem)\n);\n\n// This is a counter that increments when a thread completed\nlet shared_done_count = sync::Arc::new(sync::Mutex::new(0));\n\n// Spawn 15 threads\nfor _ in 0..15 {\n    let cloned_sem = shared_sem.clone();\n    let cloned_done_state = shared_done_count.clone();\n    let thread = thread::spawn(move || {\n        let mut local_sem = cloned_sem.lock().unwrap();\n\n        // Get required delay\n        let calculated_delay = local_sem.calc_delay();\n        drop(local_sem);\n\n        // If delay exists, sleep it\n        if let Some(delay) = calculated_delay {\n            dbg!(\u0026delay);\n            thread::sleep(delay);\n        }\n\n        // Mark the thread is done\n        let mut local_done_count = cloned_done_state.lock().unwrap();\n        *local_done_count += 1;\n\n    });\n}\n\n// So sleep 1 second (add some millis to let threads complete incrementing)\nthread::sleep(time::Duration::from_secs(1) + time::Duration::from_millis(50));\nlet cloned_done_count = shared_done_count.clone();\nlet current_done = cloned_done_count.lock().unwrap();\n\n// And then maximum 10 threads should be completed\n// after 1 second sleeping\n// (the first 5 with no delay and the another 5 after 1 second)\nassert_eq!(*current_done, 10);\n```\n\n## Features\n* Calculated delay for sleep can be used with any async/await runtime backend or with threads\n* Minimum memory used to save calls data\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeknowny%2Fraliguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeknowny%2Fraliguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeknowny%2Fraliguard/lists"}