mirror of
https://github.com/kikito/cron.lua.git
synced 2024-12-19 18:34:20 +00:00
removed unused files for the demo
This commit is contained in:
parent
0948dd03ae
commit
637dc1b66e
12
.travis.yml
12
.travis.yml
@ -1,12 +0,0 @@
|
|||||||
language: erlang
|
|
||||||
|
|
||||||
env:
|
|
||||||
- LUA=""
|
|
||||||
- LUA="luajit"
|
|
||||||
|
|
||||||
install:
|
|
||||||
- sudo apt-get install luajit
|
|
||||||
- sudo apt-get install luarocks
|
|
||||||
- sudo luarocks install busted
|
|
||||||
|
|
||||||
script: "busted"
|
|
@ -1,7 +0,0 @@
|
|||||||
# cron.lua changelog
|
|
||||||
|
|
||||||
## v 2.0.0
|
|
||||||
|
|
||||||
* Removed all 'tagged' subsystems
|
|
||||||
* Removed all internal management of state (entries). Invididual clocks are now exposed to the user directly.
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
|||||||
Copyright (c) 2011 Enrique García Cota
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
|
||||||
copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included
|
|
||||||
in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
||||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,139 +0,0 @@
|
|||||||
local cron = require 'cron'
|
|
||||||
|
|
||||||
describe( 'cron', function()
|
|
||||||
|
|
||||||
local counter
|
|
||||||
local function count(amount)
|
|
||||||
amount = amount or 1
|
|
||||||
counter = counter + amount
|
|
||||||
end
|
|
||||||
local countable = setmetatable({}, {__call = count})
|
|
||||||
|
|
||||||
before_each(function()
|
|
||||||
counter = 0
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
describe('clock', function()
|
|
||||||
|
|
||||||
describe(':update', function()
|
|
||||||
it('throws an error if dt is not positive', function()
|
|
||||||
local clock = cron.every(1, count)
|
|
||||||
assert.error(function() clock:update() end)
|
|
||||||
assert.error(function() clock:update(-1) end)
|
|
||||||
assert.not_error(function() clock:update(1) end)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe(':reset', function()
|
|
||||||
it('defaults to 0', function()
|
|
||||||
local clock = cron.every(1, count)
|
|
||||||
clock:update(1)
|
|
||||||
clock:reset(0)
|
|
||||||
assert.equal(clock.running, 0)
|
|
||||||
end)
|
|
||||||
it('throws an error if dt is not positive', function()
|
|
||||||
local clock = cron.every(1, count)
|
|
||||||
assert.error(function() clock:reset(-1) end)
|
|
||||||
assert.error(function() clock:reset('foo') end)
|
|
||||||
assert.not_error(function() clock:reset() end)
|
|
||||||
assert.not_error(function() clock:reset(1) end)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
describe('.after', function()
|
|
||||||
it('checks parameters', function()
|
|
||||||
assert.error(function() cron.after('error', count) end)
|
|
||||||
assert.error(function() cron.after(2, 'error') end)
|
|
||||||
assert.error(function() cron.after(-2, count) end)
|
|
||||||
assert.error(function() cron.after(2, {}) end)
|
|
||||||
assert.not_error(function() cron.after(2, count) end)
|
|
||||||
assert.not_error(function() cron.after(2, countable) end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('produces a clock that executes actions only once, at the right time', function()
|
|
||||||
local c1 = cron.after(2, count)
|
|
||||||
local c2 = cron.after(4, count)
|
|
||||||
|
|
||||||
-- 1
|
|
||||||
c1:update(1)
|
|
||||||
assert.equal(counter, 0)
|
|
||||||
c2:update(1)
|
|
||||||
assert.equal(counter, 0)
|
|
||||||
|
|
||||||
-- 2
|
|
||||||
c1:update(1)
|
|
||||||
assert.equal(counter, 1)
|
|
||||||
c2:update(1)
|
|
||||||
assert.equal(counter, 1)
|
|
||||||
|
|
||||||
-- 3
|
|
||||||
c1:update(1)
|
|
||||||
assert.equal(counter, 1)
|
|
||||||
c2:update(1)
|
|
||||||
assert.equal(counter, 1)
|
|
||||||
|
|
||||||
-- 4
|
|
||||||
c1:update(1)
|
|
||||||
assert.equal(counter, 1)
|
|
||||||
c2:update(1)
|
|
||||||
assert.equal(counter, 2)
|
|
||||||
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('produces a clock that can be expired', function()
|
|
||||||
local c1 = cron.after(2, count)
|
|
||||||
assert.is_false(c1:update(1))
|
|
||||||
assert.is_true(c1:update(1))
|
|
||||||
assert.is_true(c1:update(1))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('Passes on parameters to the callback', function()
|
|
||||||
local c1 = cron.after(1, count, 2)
|
|
||||||
c1:update(1)
|
|
||||||
assert.equal(counter, 2)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe('.every', function()
|
|
||||||
it('checks parameters', function()
|
|
||||||
assert.error(function() cron.every('error', count) end)
|
|
||||||
assert.error(function() cron.every(2, 'error') end)
|
|
||||||
assert.error(function() cron.every(-2, count) end)
|
|
||||||
assert.error(function() cron.every(-2, {}) end)
|
|
||||||
assert.not_error(function() cron.every(2, count) end)
|
|
||||||
assert.not_error(function() cron.every(2, countable) end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('Invokes callback periodically', function()
|
|
||||||
local c = cron.every(3, count)
|
|
||||||
|
|
||||||
c:update(1)
|
|
||||||
assert.equal(counter, 0)
|
|
||||||
|
|
||||||
c:update(2)
|
|
||||||
assert.equal(counter, 1)
|
|
||||||
|
|
||||||
c:update(2)
|
|
||||||
assert.equal(counter, 1)
|
|
||||||
|
|
||||||
c:update(1)
|
|
||||||
assert.equal(counter, 2)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('Executes the same action multiple times on a single update if appropiate', function()
|
|
||||||
local c = cron.every(1, count)
|
|
||||||
c:update(2)
|
|
||||||
assert.equal(counter, 2)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('Respects parameters', function()
|
|
||||||
local c = cron.every(1, count, 2)
|
|
||||||
c:update(2)
|
|
||||||
assert.equal(counter, 4)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
end)
|
|
Loading…
Reference in New Issue
Block a user