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

SystemClock

public static class SystemClock
Time related delegates used to support different compilation targets and to improve testability of the code.
using System; using System.Threading; using System.Threading.Tasks; namespace Polly.Utilities { public static class SystemClock { public static Action<TimeSpan, CancellationToken> Sleep = delegate(TimeSpan timeSpan, CancellationToken cancellationToken) { if (cancellationToken.WaitHandle.WaitOne(timeSpan)) cancellationToken.ThrowIfCancellationRequested(); }; public static Func<TimeSpan, CancellationToken, Task> SleepAsync = Task.Delay; public static Func<DateTime> UtcNow = () => DateTime.UtcNow; public static void Reset() { Sleep = delegate(TimeSpan timeSpan, CancellationToken cancellationToken) { if (cancellationToken.WaitHandle.WaitOne(timeSpan)) cancellationToken.ThrowIfCancellationRequested(); }; SleepAsync = Task.Delay; UtcNow = (() => DateTime.UtcNow); } } }