2016-09-03 19:46:20 +02:00
|
|
|
dofile(minetest.get_modpath("profnsched").."/queue.lua")
|
|
|
|
|
|
|
|
local jobs = {}
|
|
|
|
local scheduler = scheduler
|
|
|
|
|
2016-10-29 16:25:57 +02:00
|
|
|
function getnjobs()
|
|
|
|
return #jobs
|
|
|
|
end
|
|
|
|
|
2016-09-03 19:46:20 +02:00
|
|
|
-- For minetest.after replacement
|
|
|
|
local function check_expired_jobs()
|
|
|
|
local time = core.get_us_time()
|
2016-10-29 16:25:57 +02:00
|
|
|
local tjobs = {}
|
2016-09-03 19:46:20 +02:00
|
|
|
for i,job in pairs(jobs) do
|
|
|
|
if time >= job.expire then
|
|
|
|
scheduler.add(1, job)
|
2016-10-29 16:25:57 +02:00
|
|
|
--jobs[i] = nil
|
|
|
|
else
|
|
|
|
tjobs[#tjobs+1] = job
|
2016-09-03 19:46:20 +02:00
|
|
|
end
|
|
|
|
end
|
2016-10-29 16:25:57 +02:00
|
|
|
jobs = tjobs
|
2016-09-03 19:46:20 +02:00
|
|
|
scheduler.asap(4, check_expired_jobs)
|
|
|
|
end
|
|
|
|
scheduler.asap(4, check_expired_jobs)
|
|
|
|
|
|
|
|
|
|
|
|
-- redefine core.after function
|
|
|
|
function minetest.after(after, func, ...)
|
|
|
|
assert(type(func) == "function", "Invalid core.after invocation")
|
|
|
|
local fname = debug.getinfo(2, "S").linedefined --imprecis
|
|
|
|
local job = {
|
|
|
|
func_code = func,
|
|
|
|
expire = core.get_us_time() + after*1000000,
|
|
|
|
arg = {...},
|
|
|
|
mod_name = core.get_last_run_mod(),
|
|
|
|
func_id = "#"..fname
|
|
|
|
}
|
|
|
|
jobs[#jobs+1] = job
|
|
|
|
end
|