mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Optimize indexes() and values()
This commit is contained in:
parent
37e8e05206
commit
452ca383f7
11 changed files with 320 additions and 260 deletions
27
src/timeout.luau
Normal file
27
src/timeout.luau
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue