Merge pull request #1939 from lightpanda-io/timer_cleanup

More aggressive timer cleanup
This commit is contained in:
Karl Seguin
2026-03-22 06:44:00 +08:00
committed by GitHub

View File

@@ -285,23 +285,23 @@ pub fn queueMicrotask(_: *Window, cb: js.Function, page: *Page) void {
} }
pub fn clearTimeout(self: *Window, id: u32) void { pub fn clearTimeout(self: *Window, id: u32) void {
var sc = self._timers.get(id) orelse return; var sc = self._timers.fetchRemove(id) orelse return;
sc.removed = true; sc.value.removed = true;
} }
pub fn clearInterval(self: *Window, id: u32) void { pub fn clearInterval(self: *Window, id: u32) void {
var sc = self._timers.get(id) orelse return; var sc = self._timers.fetchRemove(id) orelse return;
sc.removed = true; sc.value.removed = true;
} }
pub fn clearImmediate(self: *Window, id: u32) void { pub fn clearImmediate(self: *Window, id: u32) void {
var sc = self._timers.get(id) orelse return; var sc = self._timers.fetchRemove(id) orelse return;
sc.removed = true; sc.value.removed = true;
} }
pub fn cancelAnimationFrame(self: *Window, id: u32) void { pub fn cancelAnimationFrame(self: *Window, id: u32) void {
var sc = self._timers.get(id) orelse return; var sc = self._timers.fetchRemove(id) orelse return;
sc.removed = true; sc.value.removed = true;
} }
const RequestIdleCallbackOpts = struct { const RequestIdleCallbackOpts = struct {
@@ -319,8 +319,8 @@ pub fn requestIdleCallback(self: *Window, cb: js.Function.Temp, opts_: ?RequestI
} }
pub fn cancelIdleCallback(self: *Window, id: u32) void { pub fn cancelIdleCallback(self: *Window, id: u32) void {
var sc = self._timers.get(id) orelse return; var sc = self._timers.fetchRemove(id) orelse return;
sc.removed = true; sc.value.removed = true;
} }
pub fn reportError(self: *Window, err: js.Value, page: *Page) !void { pub fn reportError(self: *Window, err: js.Value, page: *Page) !void {
@@ -704,7 +704,6 @@ const ScheduleCallback = struct {
const window = page.window; const window = page.window;
if (self.removed) { if (self.removed) {
_ = window._timers.remove(self.timer_id);
self.deinit(); self.deinit();
return null; return null;
} }