add rm and addFile to multitask
This commit is contained in:
parent
ee2b2fe10f
commit
c2827ce3a8
@ -3,18 +3,41 @@ local mt = {}
|
|||||||
mt.newPool = function()
|
mt.newPool = function()
|
||||||
local pool = {}
|
local pool = {}
|
||||||
pool.threads = {}
|
pool.threads = {}
|
||||||
|
pool.namedThreads = {}
|
||||||
pool.threadcount = 0
|
pool.threadcount = 0
|
||||||
|
|
||||||
pool.clear = function()
|
pool.clear = function()
|
||||||
pool.threads = {}
|
pool.threads = {}
|
||||||
|
pool.namedThreads = {}
|
||||||
|
pool.threadcount = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
pool.add = function(fn, options)
|
pool.add = function(fn, options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
options.co = coroutine.create(fn)
|
options.co = coroutine.create(fn)
|
||||||
pool.threads[options.co] = options
|
pool.threads[options.co] = options
|
||||||
|
if options.name then
|
||||||
|
pool.namedThreads[options.name] = options
|
||||||
|
end
|
||||||
pool.threadcount = pool.threadcount + 1
|
pool.threadcount = pool.threadcount + 1
|
||||||
os.queueEvent("pool_fn_added",options,pool)
|
os.queueEvent("pool_fn_added",options,pool)
|
||||||
|
return options.co
|
||||||
|
end
|
||||||
|
|
||||||
|
pool.rm = function(name)
|
||||||
|
if not pool.namedThreads[name] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
pool.threads[pool.namedThreads[name].co] = nil
|
||||||
|
pool.namedThreads[name] = nil
|
||||||
|
pool.threadcount = pool.threadcount - 1
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
pool.addFile = function(filename, options)
|
||||||
|
pool.add(function()
|
||||||
|
dofile(filename)
|
||||||
|
end,options)
|
||||||
end
|
end
|
||||||
|
|
||||||
pool.run = function(terminable)
|
pool.run = function(terminable)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
["version"] = "0.1.0",
|
["version"] = "0.1.1",
|
||||||
["dependencies"] = {},
|
["dependencies"] = {},
|
||||||
["description"] = "Adds convinientish multitasking functionality.",
|
["description"] = "Adds convinientish multitasking functionality.",
|
||||||
["files"] = {
|
["files"] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user