Skip to content

Commit b33d50e

Browse files
PytechNoclaude
andcommitted
Sleep until a task timer is due before waking it
The Luau task scheduler slept once with setTimeout and then resumed the earliest timer without checking the clock. Host timers can fire about a millisecond early, so task.wait(0.03) could return 0.0299, which failed the task library test on main's first CI run. The scheduler now sleeps again until the timer's wake time has passed, so task.wait always returns at least the time requested, as on Roblox. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f149aaa commit b33d50e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/workers/projectRuntime.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,12 @@ export const LUAU_TASK_BOOTSTRAP = `
964964
end
965965
if #timers == 0 then return end
966966
967+
-- Host timers can fire a little early, so sleep again until the timer is due.
967968
local remaining = timers[1].wake - clock()
968-
if remaining > 0 then sleep(remaining) end
969+
while remaining > 0 do
970+
sleep(remaining)
971+
remaining = timers[1].wake - clock()
972+
end
969973
local due = popTimer()
970974
resume(due.thread, due.args)
971975
end

0 commit comments

Comments
 (0)