refactor entry update method

This commit is contained in:
kikito 2012-10-28 17:16:32 +01:00
parent b855d79bb9
commit a7fcdd2b1b

View File

@ -46,7 +46,7 @@ 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))
return true entries[self] = nil
end end
end end
@ -84,9 +84,7 @@ end
function cron.update(dt) function cron.update(dt)
assert(type(dt) == "number" and dt >= 0, "dt must be a non-negative number") assert(type(dt) == "number" and dt >= 0, "dt must be a non-negative number")
for id, entry in pairs(entries) do for _, entry in pairs(entries) do entry:update(dt) end
if entry:update(dt) then entries[id] = nil end
end
end end
return cron return cron