comparison util/throttle.lua @ 4541:05f5ec99da77

Merge with trunk
author Matthew Wild <mwild1@gmail.com>
date Sun, 22 Jan 2012 22:55:49 +0000
parents fc8a22936b3c
children 0e9a5b63206a
comparison
equal deleted inserted replaced
4530:40905e7bf680 4541:05f5ec99da77
1 1
2 local gettime = require "socket".gettime; 2 local gettime = require "socket".gettime;
3 local setmetatable = setmetatable;
3 4
4 module "throttle" 5 module "throttle"
5 6
6 local throttle = {}; 7 local throttle = {};
7 local throttle_mt = { __index = throttle }; 8 local throttle_mt = { __index = throttle };
31 else 32 else
32 local balance = self.balance; 33 local balance = self.balance;
33 if split then 34 if split then
34 self.balance = 0; 35 self.balance = 0;
35 end 36 end
36 return false, balance, (cost-self.balance); 37 return false, balance, (cost-balance);
37 end 38 end
38 end 39 end
39 40
40 function create(max, period) 41 function create(max, period)
41 return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt); 42 return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt);