mirror of
https://github.com/kikito/cron.lua.git
synced 2024-12-19 18:34:20 +00:00
Add doFor function that runs the callback on every update until the timer expires.
This commit is contained in:
parent
b0127a3f14
commit
0c1f7a5e88
15
cron.lua
15
cron.lua
@ -60,6 +60,15 @@ local function updatePeriodicEntry(self, dt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function updateLimitedEntry(self, dt)
|
||||||
|
self.running = self.running + dt
|
||||||
|
|
||||||
|
self.callback(unpack(self.args))
|
||||||
|
if self.running >= self.time then
|
||||||
|
cron.cancel(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function addTags(...)
|
local function addTags(...)
|
||||||
local tags = {...}
|
local tags = {...}
|
||||||
local len = #tags
|
local len = #tags
|
||||||
@ -151,6 +160,11 @@ function cron.every(time, callback, ...)
|
|||||||
return newEntry(time, callback, updatePeriodicEntry, ...)
|
return newEntry(time, callback, updatePeriodicEntry, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function cron.doFor(time, callback, ...)
|
||||||
|
checkTimeAndCallback(time, callback)
|
||||||
|
return newEntry(time, callback, updateLimitedEntry, ...)
|
||||||
|
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")
|
||||||
|
|
||||||
@ -174,4 +188,3 @@ end
|
|||||||
cron.reset()
|
cron.reset()
|
||||||
|
|
||||||
return cron
|
return cron
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user