From dcf0194a2ff90bcd415cfc2b5ef7ae47902acaab Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 29 Apr 2022 19:27:52 -0700 Subject: [PATCH] max_timer: don't call callback in the same tick anymore --- src/max_timer.zig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/max_timer.zig b/src/max_timer.zig index 5c3061e1c..89e1c60b6 100644 --- a/src/max_timer.zig +++ b/src/max_timer.zig @@ -47,8 +47,7 @@ pub fn MaxTimer(comptime cb: fn (*libuv.Timer) void) type { }).callback); // The maximum time can't be less than the interval otherwise this - // will just constantly fire. - if (max < min) return error.MaxShorterThanTimer; + // will just constantly fire. if (max < min) return error.MaxShorterThanTimer; return Self{ .timer = timer, .min = min, @@ -98,13 +97,13 @@ pub fn MaxTimer(comptime cb: fn (*libuv.Timer) void) type { // If we are past the max time, we run the timer now. try self.timer.stop(); self.timer.loop().updateTime(); - if (self.timer.loop().now() - self.last > self.max) { - @call(.{ .modifier = .always_inline }, cb, .{&self.timer}); - return; - } + const timeout = if (self.timer.loop().now() - self.last > self.max) + 0 + else + self.min; // We still have time, restart the timer so that it is min time away. - try self.timer.start(cb, self.min, 0); + try self.timer.start(cb, timeout, 0); } }; }