Software /
code /
prosody
Comparison
util/throttle.lua @ 6777:5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 21 Feb 2015 10:36:37 +0100 |
parent | 4952:0e9a5b63206a |
child | 7988:dc758422d896 |
comparison
equal
deleted
inserted
replaced
6774:3965662ae091 | 6777:5de6b93d0190 |
---|---|
1 | 1 |
2 local gettime = require "socket".gettime; | 2 local gettime = require "socket".gettime; |
3 local setmetatable = setmetatable; | 3 local setmetatable = setmetatable; |
4 local floor = math.floor; | 4 local floor = math.floor; |
5 | 5 |
6 module "throttle" | 6 local _ENV = nil; |
7 | 7 |
8 local throttle = {}; | 8 local throttle = {}; |
9 local throttle_mt = { __index = throttle }; | 9 local throttle_mt = { __index = throttle }; |
10 | 10 |
11 function throttle:update() | 11 function throttle:update() |
37 end | 37 end |
38 return false, balance, (cost-balance); | 38 return false, balance, (cost-balance); |
39 end | 39 end |
40 end | 40 end |
41 | 41 |
42 function create(max, period) | 42 local function create(max, period) |
43 return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt); | 43 return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt); |
44 end | 44 end |
45 | 45 |
46 return _M; | 46 return { |
47 create = create; | |
48 }; |