<PackageReference Include="Polly" Version="8.5.2" />

SingleHealthMetrics

using Polly.Utilities; using System; using System.Runtime.CompilerServices; namespace Polly.CircuitBreaker { internal sealed class SingleHealthMetrics : IHealthMetrics { private readonly long _samplingDuration; [System.Runtime.CompilerServices.Nullable(2)] private HealthCount _current; public SingleHealthMetrics(TimeSpan samplingDuration) { _samplingDuration = samplingDuration.Ticks; } public void IncrementSuccess_NeedsLock() { ActualiseCurrentMetric_NeedsLock().Successes++; } public void IncrementFailure_NeedsLock() { ActualiseCurrentMetric_NeedsLock().Failures++; } public void Reset_NeedsLock() { _current = null; } [System.Runtime.CompilerServices.NullableContext(1)] public HealthCount GetHealthCount_NeedsLock() { return ActualiseCurrentMetric_NeedsLock(); } [System.Runtime.CompilerServices.NullableContext(1)] private HealthCount ActualiseCurrentMetric_NeedsLock() { long ticks = SystemClock.UtcNow().Ticks; if (_current == null || ticks - _current.StartedAt >= _samplingDuration) _current = new HealthCount { StartedAt = ticks }; return _current; } } }