mirror of
https://github.com/kikito/cron.lua.git
synced 2024-12-19 18:34:20 +00:00
cancel is also working, with tests
This commit is contained in:
parent
aaa9741b3c
commit
63152e9d1b
4
cron.lua
4
cron.lua
@ -48,6 +48,10 @@ function cron.reset()
|
||||
entries = {}
|
||||
end
|
||||
|
||||
function cron.cancel(id)
|
||||
entries[id] = nil
|
||||
end
|
||||
|
||||
function cron.after(time, callback, ...)
|
||||
checkTimeAndCallback(time, callback)
|
||||
return newEntry(time, callback, updateTimedEntry, ...)
|
||||
|
@ -22,7 +22,7 @@ context( 'cron', function()
|
||||
end)
|
||||
|
||||
context('reset', function()
|
||||
test('Should cancel all actions', function()
|
||||
test('Should cancel all timed actions', function()
|
||||
cron.after(1, count)
|
||||
cron.after(2, count)
|
||||
cron.update(1)
|
||||
@ -31,6 +31,16 @@ context( 'cron', function()
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
end)
|
||||
|
||||
test('Should cancel all periodical actions', function()
|
||||
cron.every(1, count)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
cron.reset()
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
context( 'after', function()
|
||||
@ -87,6 +97,31 @@ context( 'cron', function()
|
||||
assert_equal(counter, 2)
|
||||
end)
|
||||
|
||||
test( 'Should respect parameters', function()
|
||||
cron.every(1, count, 2)
|
||||
cron.update(2)
|
||||
assert_equal(counter, 4)
|
||||
end)
|
||||
end)
|
||||
|
||||
context( 'cancel', function()
|
||||
test( 'Should allow the cancelation of timed actions', function()
|
||||
local id = cron.after(1, count)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
cron.cancel(id)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
end)
|
||||
|
||||
test( 'Should allow the cancelation of periodical actions', function()
|
||||
local id = cron.every(1, count)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
cron.cancel(id)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user