Module helpers

Source
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)