adapt scheduleCallback to new implementation

This is currently a hack and omits many things; I'll come up with an actual solution.
This commit is contained in:
Halil Durak
2026-02-02 13:35:53 +03:00
parent b02c0f3656
commit 12fe119d6b

View File

@@ -545,11 +545,19 @@ fn scheduleCallback(self: *Window, cb: js.Function.Temp, delay_ms: u32, opts: Sc
}; };
gop.value_ptr.* = callback; gop.value_ptr.* = callback;
try page.scheduler.add(callback, ScheduleCallback.run, delay_ms, .{ //try page.scheduler.add(callback, ScheduleCallback.run, delay_ms, .{
.name = opts.name, // .name = opts.name,
.low_priority = opts.low_priority, // .low_priority = opts.low_priority,
.finalizer = ScheduleCallback.cancelled, // .finalizer = ScheduleCallback.cancelled,
}); //});
try page.scheduler.after(
.{ .priority = .high },
ScheduleCallback,
callback,
delay_ms,
ScheduleCallback.run,
);
return timer_id; return timer_id;
} }
@@ -591,15 +599,14 @@ const ScheduleCallback = struct {
self.page.releaseArena(self.arena); self.page.releaseArena(self.arena);
} }
fn run(ctx: *anyopaque) !?u32 { fn run(_: *Scheduler, self: *ScheduleCallback) !Scheduler.AfterAction {
const self: *ScheduleCallback = @ptrCast(@alignCast(ctx));
const page = self.page; const page = self.page;
const window = page.window; const window = page.window;
if (self.removed) { if (self.removed) {
_ = window._timers.remove(self.timer_id); _ = window._timers.remove(self.timer_id);
self.deinit(); self.deinit();
return null; return .dont_repeat;
} }
var ls: js.Local.Scope = undefined; var ls: js.Local.Scope = undefined;
@@ -626,11 +633,11 @@ const ScheduleCallback = struct {
} }
ls.local.runMicrotasks(); ls.local.runMicrotasks();
if (self.repeat_ms) |ms| { if (self.repeat_ms) |ms| {
return ms; return .repeat(@intCast(ms));
} }
defer self.deinit(); defer self.deinit();
_ = window._timers.remove(self.timer_id); _ = window._timers.remove(self.timer_id);
return null; return .dont_repeat;
} }
}; };