Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ public static void ElapsedMilliseconds_WithinExpectedWindow()

private static void Sleep(int milliseconds)
{
if (PlatformDetection.IsBrowser)
{
// The browser's monotonic clock (performance.now) has a coarse, security-clamped
// resolution and blocking waits don't advance real time on the single browser thread,
// so a fixed-timeout WaitOne isn't guaranteed to move the Stopwatch past its resolution
// boundary. Spin until at least one TimeSpan tick of elapsed time is observable so that
// callers relying on a measurable delta (e.g. Elapsed > TimeSpan.Zero) behave reliably.
long start = Stopwatch.GetTimestamp();
long minTicks = Math.Max(1, Stopwatch.Frequency / TimeSpan.TicksPerSecond);
do
{
s_sleepEvent.WaitOne(milliseconds);
}
while (Stopwatch.GetTimestamp() - start < minTicks);

return;
Comment thread
pavelsavara marked this conversation as resolved.
}

s_sleepEvent.WaitOne(milliseconds);
}
}
Expand Down
Loading