From a458ef365e3ace2e51e1bf0c2edefa5d02d032a8 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Thu, 6 Nov 2025 17:31:17 +0800 Subject: Fix 0ms timer. --- include/cru/base/Timer.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/cru/base/Timer.h b/include/cru/base/Timer.h index 955296b7..5508bccf 100644 --- a/include/cru/base/Timer.h +++ b/include/cru/base/Timer.h @@ -32,13 +32,17 @@ class TimerRegistry : public Object { std::chrono::milliseconds NextTimeout( std::chrono::steady_clock::time_point now) const { - return std::chrono::duration_cast( - interval - (now - created) % interval); + return interval == std::chrono::milliseconds::zero() + ? std::chrono::milliseconds::zero() + : std::chrono::duration_cast( + interval - (now - created) % interval); } bool Update(std::chrono::steady_clock::time_point now) { auto next_trigger = - last_check - (last_check - created) % interval + interval; + interval == std::chrono::milliseconds::zero() + ? last_check + : last_check - (last_check - created) % interval + interval; if (now >= next_trigger) { last_check = next_trigger; return true; -- cgit v1.2.3