Function calculate_proportional_time_adjustment

Source
pub fn calculate_proportional_time_adjustment(
    last_refresh: Instant,
    now: Instant,
    elapsed: Duration,
    window_duration: Duration,
    tokens_added: usize,
    max_tokens: usize,
) -> Instant
Expand description

Calculate the proportional time adjustment for partial token refill

When tokens are partially refilled, the last refresh time needs to be adjusted proportionally to maintain accurate rate limiting.

§Arguments

  • last_refresh - The last refresh time
  • now - Current time
  • elapsed - Time elapsed since last refresh
  • window_duration - Duration of the rate limiting window
  • tokens_added - Number of tokens that were added
  • max_tokens - Maximum number of tokens in the bucket

§Returns

The adjusted last refresh time