mirror of
https://github.com/kikito/cron.lua.git
synced 2024-12-19 18:34:20 +00:00
every is working. minor tests outstanding
This commit is contained in:
parent
e014cee5aa
commit
aaa9741b3c
5
cron.lua
5
cron.lua
@ -36,13 +36,12 @@ end
|
||||
local function updatePeriodicEntry(self, dt)
|
||||
self.running = self.running + dt
|
||||
|
||||
if self.running >= self.time then
|
||||
while self.running >= self.time do
|
||||
self.callback(unpack(self.args))
|
||||
self.running=0
|
||||
self.running = self.running - self.time
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local cron = {}
|
||||
|
||||
function cron.reset()
|
||||
|
@ -70,16 +70,23 @@ context( 'cron', function()
|
||||
end)
|
||||
|
||||
test( 'Should execute periodical actions periodically', function()
|
||||
cron.every(2, count)
|
||||
cron.every(3, count)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 0)
|
||||
cron.update(1)
|
||||
cron.update(2)
|
||||
assert_equal(counter, 1)
|
||||
cron.update(2)
|
||||
assert_equal(counter, 2)
|
||||
assert_equal(counter, 1)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 2)
|
||||
end)
|
||||
|
||||
test( 'Should execute the same action multiple times on a single update if appropiate', function()
|
||||
cron.every(1, count)
|
||||
cron.update(2)
|
||||
assert_equal(counter, 2)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user