Expand description
Helper utilities for rate limiting Common helpers for rate limiter implementations
This module provides shared utility functions for timestamp cleanup, token refill calculations, and other common rate limiting operations to reduce code duplication across different rate limiter implementations.
Functionsยง
- calculate_
proportional_ time_ adjustment - Calculate the proportional time adjustment for partial token refill
- calculate_
proportional_ time_ adjustment_ ns - Calculate proportional time adjustment for nanosecond-based rate limiters
- calculate_
token_ refill - Calculate the number of tokens to refill based on elapsed time
- calculate_
token_ refill_ ns - Calculate token refill for nanosecond-based rate limiters
- cleanup_
old_ timestamps - Clean up timestamps older than the specified cutoff time
- cleanup_
timestamps_ by_ duration - Clean up timestamps older than the specified duration from now
- record_
timestamp_ with_ cleanup - Record a new timestamp and perform cleanup if needed
- refill_
tokens_ with_ time_ adjustment - Calculate tokens available after time-based refill
- should_
perform_ full_ reset - Check if enough time has passed for a full window reset
- should_
perform_ full_ reset_ ns - Check if enough time has passed for a full window reset (nanosecond version)