mirror of
https://github.com/kikito/cron.lua.git
synced 2024-12-19 18:34:20 +00:00
small update refactoring
This commit is contained in:
parent
f6f8648c4e
commit
2fc72cf66d
9
cron.lua
9
cron.lua
@ -25,11 +25,11 @@ local function newEntry(time, callback, update, ...)
|
|||||||
return entry
|
return entry
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateTimedEntry(self, dt)
|
local function updateTimedEntry(self, dt) -- returns true if expired
|
||||||
self.running = self.running + dt
|
self.running = self.running + dt
|
||||||
if self.running >= self.time then
|
if self.running >= self.time then
|
||||||
self.callback(unpack(self.args))
|
self.callback(unpack(self.args))
|
||||||
self.expired = true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -68,11 +68,10 @@ function cron.update(dt)
|
|||||||
local expired = {}
|
local expired = {}
|
||||||
|
|
||||||
for _, entry in pairs(entries) do
|
for _, entry in pairs(entries) do
|
||||||
entry:update(dt, runningTime)
|
if entry:update(dt, runningTime) then table.insert(expired,entry) end
|
||||||
if entry.expired then expired[entry] = entry end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, entry in pairs(expired) do entries[entry] = nil end
|
for i=1, #expired do entries[expired[i]] = nil end
|
||||||
end
|
end
|
||||||
|
|
||||||
return cron
|
return cron
|
||||||
|
Loading…
Reference in New Issue
Block a user