changes
This commit is contained in:
47
koptilnya/libs/workers.txt
Normal file
47
koptilnya/libs/workers.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
WORKERS = {}
|
||||
WORKERS_QUOTA = 0.5
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user