Fix miscellaneous bugs

This commit is contained in:
v 2021-02-13 19:26:33 +00:00
parent eeb9433158
commit 4d2a17e9a7
2 changed files with 10 additions and 4 deletions

View File

@ -12,12 +12,14 @@ mt.newPool = function(pool_options)
pool.clear = function()
pool.threads = {}
pool.namedThreads = {}
pool.byID = {}
pool.threadcount = 0
end
local idcount = 0
pool.add = function(fn, options)
options = options or {}
if not fn then error("expected function",2) end
options.co = coroutine.create(function() local retv = fn(options) if retv~=nil then options.retv=retv end os.queueEvent("ignore_this") end)
options.fn = fn
options.id = idcount
@ -29,7 +31,7 @@ mt.newPool = function(pool_options)
pool.byID[options.id] = options
pool.threadcount = pool.threadcount + 1
os.queueEvent("pool_fn_added",options,pool)
return options.co
return options
end
pool.rm = function(name)
@ -74,14 +76,16 @@ mt.newPool = function(pool_options)
for thread, options in pairs(pool.threads) do
if coroutine.status(thread) ~= "dead" then
if event[1] == options.filter or options.filter == nil then
local x,e,y = coroutine.resume(thread,unpack(event))
options.filter = y
local x,e = coroutine.resume(thread,unpack(event))
if not x then
os.queueEvent("pool_fn_crash",options.id,pool.id,e)
pool.rm(options)
if pool_options.crash_on_error then
error(e)
end
else
options.filter = e
end
end
else
@ -99,6 +103,8 @@ mt.newPool = function(pool_options)
local to_match = nil
if type(v) == "table" then
to_match = v.id
elseif type(v) == "thread" then
to_match = pool.threads[v].id
elseif type(name)=="number" then
if not pool.byID[name] then
error("no thread with ID "..name)

View File

@ -1,5 +1,5 @@
{
["version"] = "0.1.2",
["version"] = "0.1.2-1",
["dependencies"] = {},
["description"] = "Adds convinientish multitasking functionality.",
["files"] = {