From 2740a7680b146c464812495b71ca790fbc211c36 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Tue, 4 Feb 2025 20:50:53 +0100 Subject: [PATCH] Stop compensating for early Timer in libuv It appears to have been fixed on the libuv side, so now Julia's timers are one millisecond too slow. --- base/asyncevent.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/base/asyncevent.jl b/base/asyncevent.jl index 8297626ee0f97..ac48226d6a0fc 100644 --- a/base/asyncevent.jl +++ b/base/asyncevent.jl @@ -116,8 +116,7 @@ mutable struct Timer function Timer(timeout::Real; interval::Real = 0.0) timeout ≥ 0 || throw(ArgumentError("timer cannot have negative timeout of $timeout seconds")) interval ≥ 0 || throw(ArgumentError("timer cannot have negative repeat interval of $interval seconds")) - # libuv has a tendency to timeout 1 ms early, so we need +1 on the timeout (in milliseconds), unless it is zero - timeoutms = ceil(UInt64, timeout * 1000) + !iszero(timeout) + timeoutms = ceil(UInt64, timeout * 1000) intervalms = ceil(UInt64, interval * 1000) loop = eventloop() @@ -139,7 +138,7 @@ end function getproperty(t::Timer, f::Symbol) if f == :timeout t.timeout_ms == 0 && return 0.0 - return (t.timeout_ms - 1) / 1000 # remove the +1ms compensation from the constructor + return t.timeout_ms / 1000 elseif f == :interval return t.interval_ms / 1000 else