Skip to content

Commit b9cf511

Browse files
authored
not use the extension to fix copilot comments
1 parent d7ef08e commit b9cf511

5 files changed

Lines changed: 10 additions & 13 deletions

File tree

src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/ConcurrencyLimiter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public sealed class ConcurrencyLimiter : RateLimiter
3232
private object Lock => _queue;
3333

3434
/// <inheritdoc />
35-
public override TimeSpan? IdleDuration => Stopwatch.GetElapsedTime(_idleSince);
35+
public override TimeSpan? IdleDuration => RateLimiterHelper.GetElapsedTime(_idleSince);
3636
/// <summary>
3737
/// Initializes the <see cref="ConcurrencyLimiter"/>.
3838
/// </summary>

src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public sealed class FixedWindowRateLimiter : ReplenishingRateLimiter
2424

2525
/// <summary>
2626
/// Function to calculate elapsed time from a given tick value.
27-
/// Defaults to the <c>Stopwatch.GetElapsedTime(long?)</c> extension which returns <see langword="null"/> when the timestamp is <see langword="null"/>.
27+
/// 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.
2828
/// In tests, this field can be reassigned via reflection to inject custom time behavior without modifying the public API.
2929
/// </summary>
30-
private readonly Func<long?, TimeSpan?> _getElapsedTime = Stopwatch.GetElapsedTime;
30+
private readonly Func<long?, TimeSpan?> _getElapsedTime = RateLimiterHelper.GetElapsedTime;
3131

3232
private readonly Timer? _renewTimer;
3333
private readonly FixedWindowRateLimiterOptions _options;

src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/RateLimiterHelper.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ namespace System.Threading.RateLimiting
77
{
88
internal static class RateLimiterHelper
99
{
10-
extension(Stopwatch)
10+
public static TimeSpan? GetElapsedTime(long? startTimestamp)
1111
{
12-
public static TimeSpan? GetElapsedTime(long? startTimestamp)
12+
if (startTimestamp is null)
1313
{
14-
if (startTimestamp is null)
15-
{
16-
return null;
17-
}
18-
19-
return Stopwatch.GetElapsedTime(startTimestamp.Value);
14+
return null;
2015
}
16+
17+
return Stopwatch.GetElapsedTime(startTimestamp.Value);
2118
}
2219
}
2320
}

src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/SlidingWindowRateLimiter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public sealed class SlidingWindowRateLimiter : ReplenishingRateLimiter
3636
private static readonly RateLimitLease FailedLease = new SlidingWindowLease(false, null);
3737

3838
/// <inheritdoc />
39-
public override TimeSpan? IdleDuration => Stopwatch.GetElapsedTime(_idleSince);
39+
public override TimeSpan? IdleDuration => RateLimiterHelper.GetElapsedTime(_idleSince);
4040

4141
/// <inheritdoc />
4242
public override bool IsAutoReplenishing => _options.AutoReplenishment;

src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public sealed class TokenBucketRateLimiter : ReplenishingRateLimiter
3434
private static readonly RateLimitLease FailedLease = new TokenBucketLease(false, null);
3535

3636
/// <inheritdoc />
37-
public override TimeSpan? IdleDuration => Stopwatch.GetElapsedTime(_idleSince);
37+
public override TimeSpan? IdleDuration => RateLimiterHelper.GetElapsedTime(_idleSince);
3838

3939
/// <inheritdoc />
4040
public override bool IsAutoReplenishing => _options.AutoReplenishment;

0 commit comments

Comments
 (0)