Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class FixedWindowRateLimiter : ReplenishingRateLimiter

/// <summary>
/// Function to calculate elapsed time from a given tick value.
/// Defaults to <see cref="RateLimiterHelper.GetElapsedTime(long?)"/>.
/// Defaults to the <see cref="RateLimiterHelper.GetElapsedTime(long?)"/> which returns <see langword="null"/> when the timestamp is <see langword="null"/>, and returns <c>Stopwatch.GetElapsedTime(long)</c> when not null.
/// In tests, this field can be reassigned via reflection to inject custom time behavior without modifying the public API.
/// </summary>
private readonly Func<long?, TimeSpan?> _getElapsedTime = RateLimiterHelper.GetElapsedTime;
Expand Down Expand Up @@ -301,7 +301,7 @@ private void ReplenishInternal(long nowTicks)
return;
}

if (RateLimiterHelper.GetElapsedTime(_lastReplenishmentTick, nowTicks) < _options.Window && !_options.AutoReplenishment)
if (Stopwatch.GetElapsedTime(_lastReplenishmentTick, nowTicks) < _options.Window && !_options.AutoReplenishment)
Comment thread
WeihanLi marked this conversation as resolved.
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ internal static class RateLimiterHelper

return Stopwatch.GetElapsedTime(startTimestamp.Value);
}

public static TimeSpan GetElapsedTime(long startTimestamp, long endTimestamp)
{
return Stopwatch.GetElapsedTime(startTimestamp, endTimestamp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void ReplenishInternal(long nowTicks)
return;
}

if (RateLimiterHelper.GetElapsedTime(_lastReplenishmentTick, nowTicks) < ReplenishmentPeriod && !_options.AutoReplenishment)
if (Stopwatch.GetElapsedTime(_lastReplenishmentTick, nowTicks) < ReplenishmentPeriod && !_options.AutoReplenishment)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private void ReplenishInternal(long nowTicks)
}
else
{
add = _fillRate * RateLimiterHelper.GetElapsedTime(_lastReplenishmentTick, nowTicks).Ticks;
add = _fillRate * Stopwatch.GetElapsedTime(_lastReplenishmentTick, nowTicks).Ticks;
}

_tokenCount = Math.Min(_options.TokenLimit, _tokenCount + add);
Expand Down
Loading