X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fthrottle.lua;h=55e1d07b3f5a836b450fc65cf23a1c31b7363e49;hb=84c934632367eac822fb6af2663032b67fd0a596;hp=2e901158096e0cc4302b2d630e8df7968186310c;hpb=cb2c1215a9a5df6c7e458dd788193aa6b41169c7;p=prosody.git 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