util.throttle: floor() internal balance calculation

This commit is contained in:
Matthew Wild 2012-07-09 02:35:47 +01:00
parent 1c1baa42c8
commit 88f2090c5b

View file

@ -1,6 +1,7 @@
local gettime = require "socket".gettime;
local setmetatable = setmetatable;
local floor = math.floor;
module "throttle"
@ -11,7 +12,7 @@ function throttle:update()
local newt = gettime();
local elapsed = newt - self.t;
self.t = newt;
local balance = self.rate * elapsed + self.balance;
local balance = floor(self.rate * elapsed) + self.balance;
if balance > self.max then
self.balance = self.max;
else