pai Networking
rate-limiter
Token bucket rate limiter for controlling API call frequency. Use Allow() for non-blocking checks or Wait() to block until a slot is available.
Install ppm install rate-limiter
Usage Example
uses rate_limiter; // 10 requests per second var limiter := Create(10); for var i := 1 to 1000 do begin // Blocks until a token is available Wait(limiter); CallExternalAPI(i); end; // Non-blocking check if Allow(limiter) then DoRequest else WriteLn('Rate limit reached');
Features
Token bucket algorithm
Configurable requests-per-second
Non-blocking Allow() check
Blocking Wait() that sleeps until ready
Thread-safe token accounting
← Back to Package Index