Changeset

4952:0e9a5b63206a

util.throttle: floor() internal balance calculation
author Matthew Wild <mwild1@gmail.com>
date Mon, 09 Jul 2012 02:35:47 +0100
parents 4950:02e5e9fa37b8
children 4953:24c2150cc8b0 4954:318624ffe74e 4973:3f7248ac1a3b
files util/throttle.lua
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/throttle.lua	Sun Jul 08 18:54:30 2012 +0100
+++ b/util/throttle.lua	Mon Jul 09 02:35:47 2012 +0100
@@ -1,6 +1,7 @@
 
 local gettime = require "socket".gettime;
 local setmetatable = setmetatable;
+local floor = math.floor;
 
 module "throttle"
 
@@ -11,7 +12,7 @@
 	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