Nikita Kruglickiy eb6144ae94 Cleaning
2021-04-03 21:08:08 +06:00

48 lines
917 B
Plaintext

WORKERS = {}
WORKERS_QUOTA = 0.4
local function execWorker(worker)
local status
while math.max(quotaAverage(), quotaUsed()) < quotaMax() * WORKERS_QUOTA do
status = worker()
if status == 1 or status == 2 then
break
end
end
return status
end
local function procWorkers()
local i = 1
while i <= #WORKERS do
local status = execWorker(WORKERS[i])
if status == 2 then
table.remove(WORKERS, i)
elseif status == 1 then
i = i + 1
else
break
end
end
if #WORKERS == 0 then
hook.remove("think", "workers_think")
end
end
function addWorker(worker)
local status = execWorker(worker)
if status ~= 2 then
if #WORKERS == 0 then
hook.add("think", "workers_think", procWorkers)
end
WORKERS[#WORKERS + 1] = worker
end
end