local gettime = require "socket".gettime;
local setmetatable = setmetatable;
+local floor = math.floor;
module "throttle"
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
if split then
self.balance = 0;
end
- return false, balance, (cost-self.balance);
+ return false, balance, (cost-balance);
end
end