# HG changeset patch # User Waqas Hussain # Date 1505669354 14400 # Node ID e3f7b6fa46ba839600c5ce6f225987f8c266878e # Parent 63e505578d4f1f196dd3fe62c078b2a0698952a3 util.throttle: Fix initial time setting (double accounting the first time) and fractional balance updates (0.1*10 was not the same as 1*1) diff -r 63e505578d4f -r e3f7b6fa46ba util/throttle.lua --- a/util/throttle.lua Tue Sep 19 23:38:08 2017 +0200 +++ b/util/throttle.lua Sun Sep 17 13:29:14 2017 -0400 @@ -12,7 +12,7 @@ local newt = gettime(); local elapsed = newt - self.t; self.t = newt; - local balance = floor(self.rate * elapsed) + self.balance; + local balance = (self.rate * elapsed) + self.balance; if balance > self.max then self.balance = self.max; else @@ -40,7 +40,7 @@ end local function create(max, period) - return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt); + return setmetatable({ rate = max / period, max = max, t = gettime(), balance = max }, throttle_mt); end return {