28 public async ValueTask
Delay(TimeSpan timeSpan, CancellationToken cancellationToken)
31 const uint DelayMinutesLimit = UInt32.MaxValue - 1;
32 Debug.Assert(DelayMinutesLimit == 4294967294,
"Delay limit assertion failure!");
34 var maxDelayIterations = 0UL;
35 if (timeSpan.TotalMilliseconds >= UInt32.MaxValue)
37 maxDelayIterations = (ulong)Math.Floor(timeSpan.TotalMilliseconds / DelayMinutesLimit);
38 logger.LogDebug(
"Breaking interval into {iterationCount} iterations", maxDelayIterations + 1);
39 timeSpan = TimeSpan.FromMilliseconds(timeSpan.TotalMilliseconds - (maxDelayIterations * DelayMinutesLimit));
42 if (maxDelayIterations > 0)
44 var longDelayTimeSpan = TimeSpan.FromMilliseconds(DelayMinutesLimit);
45 for (var i = 0UL; i < maxDelayIterations; ++i)
47 logger.LogTrace(
"Long delay #{iteration}...", i + 1);
48 await Task.Delay(longDelayTimeSpan, cancellationToken);
51 logger.LogTrace(
"Final delay iteration #{iteration}...", maxDelayIterations + 1);
54 await Task.Delay(timeSpan, cancellationToken);