Removed system threaded connections, soon to be replaced by proxies

This commit is contained in:
Ryan Ward 2023-07-04 16:00:37 -04:00
parent 81fc7b95c9
commit acc94ea17e
5 changed files with 121 additions and 64 deletions

View File

@ -2389,7 +2389,7 @@ end
function multi.print(...)
if multi.defaultSettings.print then
local t = {}
for i,v in pairs(multi.pack(...)) do t[#t+1] = tostring(v) end
for i,v in ipairs(multi.pack(...)) do t[#t+1] = tostring(v) end
io.write("\x1b[94mINFO:\x1b[0m " .. table.concat(t," ") .. "\n")
end
end
@ -2397,7 +2397,7 @@ end
function multi.warn(...)
if multi.defaultSettings.warn then
local t = {}
for i,v in pairs(multi.pack(...)) do t[#t+1] = tostring(v) end
for i,v in ipairs(multi.pack(...)) do t[#t+1] = tostring(v) end
io.write("\x1b[93mWARNING:\x1b[0m " .. table.concat(t," ") .. "\n")
end
end
@ -2414,7 +2414,7 @@ end
function multi.success(...)
local t = {}
for i,v in pairs(multi.pack(...)) do t[#t+1] = tostring(v) end
for i,v in ipairs(multi.pack(...)) do t[#t+1] = tostring(v) end
io.write("\x1b[92mSUCCESS:\x1b[0m " .. table.concat(t," ") .. "\n")
end
@ -2431,7 +2431,6 @@ multi.SetName = multi.setName
local _os = os.exit
function os.exit(n)
print("ERROR_"..n)
multi.OnExit:Fire(n or 0)
_os(n)
end

View File

@ -381,3 +381,4 @@ function multi:newSystemThreadedConnection(name)
return c
end
require("multi.integration.sharedExtensions")

View File

@ -153,3 +153,4 @@ function multi:newSystemThreadedConnection(name)
GLOBAL[name or "_"] = conn
return conn
end
require("multi.integration.sharedExtensions")

View File

@ -22,26 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
]]
local function copy(obj)
if type(obj) ~= 'table' then return obj end
local res = {}
for k, v in pairs(obj) do res[copy(k)] = copy(v) end
return res
end
function tprint (tbl, indent)
if not indent then indent = 0 end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
tprint(v, indent+1)
else
print(formatting .. tostring(v))
end
end
end
local multi, thread = require("multi"):init()
-- Returns a handler that allows a user to interact with an object on another thread!
@ -73,6 +53,12 @@ function multi:newProxy(list)
local multi, thread = nil, nil
function c:init()
local multi, thread = nil, nil
local function copy(obj)
if type(obj) ~= 'table' then return obj end
local res = {}
for k, v in pairs(obj) do res[copy(k)] = copy(v) end
return res
end
if not(c.is_init) then
c.is_init = true
local multi, thread = require("multi"):init()
@ -132,6 +118,12 @@ function multi:newProxy(list)
end).OnError(multi.error)
return self
else
local function copy(obj)
if type(obj) ~= 'table' then return obj end
local res = {}
for k, v in pairs(obj) do res[copy(k)] = copy(v) end
return res
end
local multi, thread = require("multi"):init()
local me = self
local funcs = copy(self.funcs)
@ -180,6 +172,12 @@ function multi:newProxy(list)
function c:getTransferable()
local cp = {}
local multi, thread = require("multi"):init()
local function copy(obj)
if type(obj) ~= 'table' then return obj end
local res = {}
for k, v in pairs(obj) do res[copy(k)] = copy(v) end
return res
end
cp.is_init = true
cp.proxy_link = self.proxy_link
cp.name = self.name

View File

@ -131,53 +131,111 @@ multi:newThread("Scheduler Thread",function()
multi.success("SystemThreadedJobQueues: Ok")
queue2 = multi:newSystemThreadedQueue("Test_Queue2"):init()
multi:newSystemThread("Test_Thread_2",function()
queue2 = THREAD.waitFor("Test_Queue2"):init()
connOut = THREAD.waitFor("ConnectionNAMEHERE"):init()
connOut(function(arg)
queue2:push("Test_Thread_2")
end)
multi:mainloop()
end).OnError(multi.error)
multi:newSystemThread("Test_Thread_3",function()
queue2 = THREAD.waitFor("Test_Queue2"):init()
connOut = THREAD.waitFor("ConnectionNAMEHERE"):init()
connOut(function(arg)
queue2:push("Test_Thread_3")
end)
multi:mainloop()
end).OnError(multi.error)
connOut = multi:newSystemThreadedConnection("ConnectionNAMEHERE"):init()
a=0
connOut(function(arg)
queue2:push("Main")
end)
for i=1,3 do
thread.sleep(.1)
connOut:Fire("Test From Main Thread: "..i.."\n")
end
thread.sleep(2)
local count = 0
multi:newThread(function()
while count < 9 do
if queue2:pop() then
count = count + 1
-- queue2 = multi:newSystemThreadedQueue("Test_Queue2"):init()
-- multi:newSystemThread("Test_Thread_2",function()
-- queue2 = THREAD.waitFor("Test_Queue2"):init()
-- connOut = THREAD.waitFor("ConnectionNAMEHERE"):init()
-- connOut(function(arg)
-- queue2:push("Test_Thread_2")
-- end)
-- multi:mainloop()
-- end).OnError(multi.error)
-- multi:newSystemThread("Test_Thread_3",function()
-- queue2 = THREAD.waitFor("Test_Queue2"):init()
-- connOut = THREAD.waitFor("ConnectionNAMEHERE"):init()
-- connOut(function(arg)
-- queue2:push("Test_Thread_3")
-- end)
-- multi:mainloop()
-- end).OnError(multi.error)
-- connOut = multi:newSystemThreadedConnection("ConnectionNAMEHERE"):init()
-- a=0
-- connOut(function(arg)
-- queue2:push("Main")
-- end)
-- for i=1,3 do
-- thread.sleep(.1)
-- connOut:Fire("Test From Main Thread: "..i.."\n")
-- end
-- thread.sleep(2)
-- local count = 0
-- multi:newThread(function()
-- while count < 9 do
-- if queue2:pop() then
-- count = count + 1
-- end
-- end
-- end).OnError(multi.error)
-- _, err = thread.hold(function() return count == 9 end,{sleep=.3})
-- if err == multi.TIMEOUT then
-- multi.error("SystemThreadedConnections: Failed")
-- end
-- multi.success("SystemThreadedConnections: Ok")
local stp = multi:newSystemThreadedProcessor(8)
local tloop = stp:newTLoop(nil, 1)
local proxy_test = false
multi:newSystemThread("Testing proxy copy THREAD",function(tloop)
local multi, thread = require("multi"):init()
tloop = tloop:init()
multi.print("tloop type:",tloop.Type)
multi.print("Testing proxies on other threads")
thread:newThread(function()
while true do
thread.hold(tloop.OnLoop)
print(THREAD_NAME,"Loopy")
end
end)
tloop.OnLoop(function(a)
print(THREAD_NAME, "Got loop...")
end)
multi:mainloop()
end, tloop:getTransferable()).OnError(multi.error)
multi.print("tloop", tloop.Type)
multi.print("tloop.OnLoop", tloop.OnLoop.Type)
thread:newThread(function()
multi.print("Testing holding on a proxy connection!")
thread.hold(tloop.OnLoop)
multi.print("Held on proxy connection... once")
thread.hold(tloop.OnLoop)
multi.print("Held on proxy connection... twice")
proxy_test = true
end).OnError(print)
thread:newThread(function()
while true do
thread.hold(tloop.OnLoop)
print(THREAD_NAME,"Loopy")
end
end).OnError(multi.error)
_, err = thread.hold(function() return count == 9 end,{sleep=.3})
if err == multi.TIMEOUT then
multi.error("SystemThreadedConnections: Failed")
end)
tloop.OnLoop(function()
print("OnLoop",THREAD_NAME)
end)
t, val = thread.hold(function()
return count == 10
end,{sleep=5})
if val == multi.TIMEOUT then
multi.error("SystemThreadedProcessor/Proxies: Failed")
os.exit(1)
end
multi.success("SystemThreadedConnections: Ok")
thread.sleep(2)
multi.success("SystemThreadedProcessor: OK")
we_good = true
os.exit(1)
end).OnError(multi.error)
multi.OnExit(function(err_or_errorcode)
print("Final status!",err_or_errorcode)
if not we_good then
multi.info("There was an error running some tests!")
return