diff options
author | Matthew Wild <mwild1@gmail.com> | 2012-07-09 02:35:47 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2012-07-09 02:35:47 +0100 |
commit | 88f2090c5b3ace2f2f07de9735fa60307a19d010 (patch) | |
tree | 7ca3fd2736ebcf704bdd2623276882d2f6967335 /util/throttle.lua | |
parent | 1c1baa42c8a2c047f938a442d776f33320013c0c (diff) | |
download | prosody-88f2090c5b3ace2f2f07de9735fa60307a19d010.tar.gz prosody-88f2090c5b3ace2f2f07de9735fa60307a19d010.zip |
util.throttle: floor() internal balance calculation
Diffstat (limited to 'util/throttle.lua')
-rw-r--r-- | util/throttle.lua | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/util/throttle.lua b/util/throttle.lua index 2e901158..55e1d07b 100644 --- a/util/throttle.lua +++ b/util/throttle.lua @@ -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 |