Rate limit guard
Lazy rate limit semaphore implementation to control your asynchronous code frequency execution
Documentation: lib.rs/raliguard
Overview
use ;
use Semaphore;
// Create a semaphore with restriction `5 tasks per 1 second`
let originl_sem = new;
// Make it sharable between treads (or you can share between tasks)
let shared_sem = new;
// This is a counter that increments when a thread completed
let shared_done_count = new;
// Spawn 10 threads
for _ in 0..10
// So sleep 1 second
sleep;
let cloned_done_count = shared_done_count.clone;
let current_done = cloned_done_count.lock.unwrap;
// And then maximum 5 threads should be completed
// after 1 second sleeping
// (<= for clocks infelicity)
assert_eq!;
Features
- Calculated delay for sleep can be used with any async/await runtime backend or with threads
- Minimum memory used to save calls data