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