Fixed newTask()
This commit is contained in:
parent
9ad2c45b8f
commit
0af807a930
@ -523,6 +523,8 @@ Added
|
|||||||
|
|
||||||
Changed
|
Changed
|
||||||
---
|
---
|
||||||
|
- multi:newTask(task) is not tied to the processor it is created on.
|
||||||
|
- `multi:getTasks()` renamed to `multi:getRunners()`, should help with confusion between multi:newTask()
|
||||||
- changed how multi adds unpack to the global namespace. Instead we capture that value into multi.unpack.
|
- changed how multi adds unpack to the global namespace. Instead we capture that value into multi.unpack.
|
||||||
- multi:newUpdater(skip, func) -- Now accepts func as the second argument. So you don't need to call OnUpdate(func) after creation.
|
- multi:newUpdater(skip, func) -- Now accepts func as the second argument. So you don't need to call OnUpdate(func) after creation.
|
||||||
- multi errors now internally call `multi.error` instead of `multi.print`
|
- multi errors now internally call `multi.error` instead of `multi.print`
|
||||||
|
|||||||
36
init.lua
36
init.lua
@ -1011,10 +1011,10 @@ function multi:newTStep(start,reset,count,set)
|
|||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
local tasks = {}
|
multi.tasks = {}
|
||||||
|
|
||||||
function multi:newTask(func)
|
function multi:newTask(func)
|
||||||
tasks[#tasks + 1] = func
|
self.tasks[#self.tasks + 1] = func
|
||||||
end
|
end
|
||||||
|
|
||||||
local scheduledjobs = {}
|
local scheduledjobs = {}
|
||||||
@ -1086,6 +1086,7 @@ function multi:newProcessor(name, nothread, priority)
|
|||||||
c.Type = multi.registerType("process", "processes")
|
c.Type = multi.registerType("process", "processes")
|
||||||
local Active = nothread or false
|
local Active = nothread or false
|
||||||
c.Name = name or ""
|
c.Name = name or ""
|
||||||
|
c.tasks = {}
|
||||||
c.threads = {}
|
c.threads = {}
|
||||||
c.startme = {}
|
c.startme = {}
|
||||||
c.parent = self
|
c.parent = self
|
||||||
@ -1175,6 +1176,20 @@ function multi:newProcessor(name, nothread, priority)
|
|||||||
c.process:Destroy()
|
c.process:Destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
c:newThread("Task Handler", function()
|
||||||
|
local self = multi:getCurrentProcess()
|
||||||
|
local function task_holder()
|
||||||
|
return #self.tasks > 0
|
||||||
|
end
|
||||||
|
while true do
|
||||||
|
if #self.tasks > 0 then
|
||||||
|
table.remove(self.tasks,1)()
|
||||||
|
else
|
||||||
|
thread.hold(task_holder)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end).OnError(multi.error)
|
||||||
|
|
||||||
table.insert(processes,c)
|
table.insert(processes,c)
|
||||||
self:create(c)
|
self:create(c)
|
||||||
return c
|
return c
|
||||||
@ -1213,7 +1228,7 @@ function multi:getThreads()
|
|||||||
return threads
|
return threads
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi:getTasks()
|
function multi:getRunners()
|
||||||
local tasks = {}
|
local tasks = {}
|
||||||
for i,v in pairs(self.Mainloop) do
|
for i,v in pairs(self.Mainloop) do
|
||||||
if not v.__ignore then
|
if not v.__ignore then
|
||||||
@ -2503,6 +2518,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
threadManager = multi:newProcessor("Global_Thread_Manager", nil, true).Start()
|
threadManager = multi:newProcessor("Global_Thread_Manager", nil, true).Start()
|
||||||
|
threadManager.tasks = multi.tasks -- The main multi interface is a bit different.
|
||||||
|
|
||||||
function multi:getThreadManagerProcess()
|
function multi:getThreadManagerProcess()
|
||||||
return threadManager
|
return threadManager
|
||||||
@ -2512,18 +2528,4 @@ function multi:getHandler()
|
|||||||
return threadManager:getHandler()
|
return threadManager:getHandler()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function task_holder()
|
|
||||||
return #tasks > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
multi:newThread("Task Handler", function()
|
|
||||||
while true do
|
|
||||||
if #tasks > 0 then
|
|
||||||
table.remove(tasks)()
|
|
||||||
else
|
|
||||||
thread.hold(task_holder)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end).OnError(multi.error)
|
|
||||||
|
|
||||||
return multi
|
return multi
|
||||||
@ -98,6 +98,11 @@ multi, thread = require("multi"):init{print=true,warn=true,error=true,debugging=
|
|||||||
-- multi:newTLoop(func, 1)
|
-- multi:newTLoop(func, 1)
|
||||||
|
|
||||||
-- multi:mainloop()
|
-- multi:mainloop()
|
||||||
|
for i = 1, 100 do
|
||||||
|
multi:newTask(function()
|
||||||
|
print("Task "..i)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
local conn = multi:newConnection()
|
local conn = multi:newConnection()
|
||||||
conn(function() print("Test 1") end)
|
conn(function() print("Test 1") end)
|
||||||
@ -113,6 +118,8 @@ conn:Fire()
|
|||||||
|
|
||||||
print(#conn)
|
print(#conn)
|
||||||
|
|
||||||
|
multi:mainloop()
|
||||||
|
|
||||||
-- local conn1, conn2, conn3 = multi:newConnection(nil,nil,true), multi:newConnection(), multi:newConnection()
|
-- local conn1, conn2, conn3 = multi:newConnection(nil,nil,true), multi:newConnection(), multi:newConnection()
|
||||||
|
|
||||||
-- local link = conn1(function()
|
-- local link = conn1(function()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user