Optimize indexes() and values()

This commit is contained in:
aaron 2025-03-27 19:27:54 +00:00
parent 37e8e05206
commit 452ca383f7
11 changed files with 320 additions and 260 deletions

27
src/timeout.luau Normal file
View file

@ -0,0 +1,27 @@
local queue = {} :: {
{ t: number, fn: () -> (), cancel: boolean }
}
local function timeout(t: number, fn: () -> ())
local handle = { t = t, fn = fn, cancel = false }
table.insert(queue, handle)
return handle
end
local function update_timeouts(dt: number)
for i = #queue, 1, -1 do
local handle = queue[i]
handle.t -= dt
if handle.cancel or handle.t <= 0 then
queue[i] = queue[#queue]
queue[#queue] = nil
if not handle.cancel then
handle.fn()
end
end
end
end
return function() return timeout, update_timeouts end