Interface IClock
- Namespace
- Yarp.ReverseProxy.Utilities
- Assembly
- Yarp.ReverseProxy.dll
Abstraction over monotonic time providers (Environment.TickCount64, Stopwatch.GetTimestamp, as opposed to DateTime).
[Obsolete("For testing only. Use TimeProvider instead.")]
public interface IClock
Properties
TickCount
Gets a value that indicates the current tick count measured as milliseconds from an arbitrary reference time. The default implementation leverages TickCount64. This is generally more efficient than GetStopwatchTime(), but provides less precision.
long TickCount { get; }
Property Value
Methods
Delay(int, CancellationToken)
Creates a cancellable task that completes after a specified time interval. This is equivalent to Delay(int, CancellationToken), and facilitates unit tests that use virtual time.
Task Delay(int millisecondsDelay, CancellationToken cancellationToken)
Parameters
millisecondsDelay
intThe number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
cancellationToken
CancellationTokenA cancellation token to observe while waiting for the task to complete.
Returns
- Task
A task that represents the time delay.
Delay(TimeSpan, CancellationToken)
Creates a cancellable task that completes after a specified time interval. This is equivalent to Delay(TimeSpan, CancellationToken), and facilitates unit tests that use virtual time.
Task Delay(TimeSpan delay, CancellationToken cancellationToken)
Parameters
delay
TimeSpanThe time span to wait before completing the returned task, or TimeSpan.FromMilliseconds(-1) to wait indefinitely.
cancellationToken
CancellationTokenA cancellation token to observe while waiting for the task to complete.
Returns
- Task
A task that represents the time delay.
GetStopwatchTime()
Gets a precise time measurement using Stopwatch as the time source.
TimeSpan GetStopwatchTime()
Returns
- TimeSpan
The time measurement.
GetUtcNow()
Gets the current time in UTC as a DateTimeOffset.
DateTimeOffset GetUtcNow()