From cb95d0dd5bc6d8c8616122c226ba5b3d1e6b99f1 Mon Sep 17 00:00:00 2001 From: Santos Date: Mon, 22 Oct 2012 20:27:49 +1100 Subject: [PATCH] A few minor changes --- cron.lua | 12 ++++-------- spec/cron_spec.lua | 2 +- spec/inspect.lua | 1 - 3 files changed, 5 insertions(+), 10 deletions(-) delete mode 120000 spec/inspect.lua diff --git a/cron.lua b/cron.lua index 7612652..3e2708b 100644 --- a/cron.lua +++ b/cron.lua @@ -25,7 +25,7 @@ local function checkTimeAndCallback(time, callback) assert(isCallable(callback), "callback must be a function") end -local entries = setmetatable({}, {__mode = "k"}) +local entries = {} local function newEntry(time, callback, update, ...) local entry = { @@ -77,15 +77,11 @@ function cron.every(time, callback, ...) end function cron.update(dt) - assert(type(dt) == "number" and dt > 0, "dt must be a positive number") + assert(type(dt) == "number" and dt >= 0, "dt must be a non-negative number") - local expired = {} - - for _, entry in pairs(entries) do - if entry:update(dt, runningTime) then table.insert(expired,entry) end + for id, entry in pairs(entries) do + if entry:update(dt) then entry[id] = nil end end - - for i=1, #expired do entries[expired[i]] = nil end end return cron diff --git a/spec/cron_spec.lua b/spec/cron_spec.lua index 979b1f3..a0ae646 100644 --- a/spec/cron_spec.lua +++ b/spec/cron_spec.lua @@ -15,7 +15,7 @@ context( 'cron', function() end) context('update', function() - test( 'Should throw an error if dt is not a positive number', function() + test( 'Should throw an error if dt is a negative number', function() assert_error(function() cron.update() end) assert_error(function() cron.update(-1) end) assert_not_error(function() cron.update(1) end) diff --git a/spec/inspect.lua b/spec/inspect.lua deleted file mode 120000 index a5f321a..0000000 --- a/spec/inspect.lua +++ /dev/null @@ -1 +0,0 @@ -../inspect.lua \ No newline at end of file