1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-22 11:17:40 +00:00

throttlee

This commit is contained in:
kepler155c@gmail.com
2017-05-14 00:53:59 -04:00
parent c34b46699b
commit 9a0c584cba
3 changed files with 20 additions and 8 deletions

View File

@@ -21,13 +21,17 @@ function Util.tryTimes(attempts, f, ...)
return unpack(result)
end
function Util.throttle()
function Util.throttle(fn)
local ts = os.time()
return function()
local timeout = .095
return function(...)
local nts = os.time()
if nts ~= ts then
if nts > ts + timeout then
ts = nts
os.sleep(0)
if fn then
fn(...)
end
end
end
end