From 8afef44252182be0f1ef99555b28150de4761d36 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Sat, 23 Mar 2019 20:54:29 -0400 Subject: [PATCH] Issue#12 Changed Modify the newThread method to allow for nameless coroutine based threads --- multi/init.lua | 7 ++++++- test.lua | 43 +++++++++---------------------------------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/multi/init.lua b/multi/init.lua index 19894e1..418bc26 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -1495,8 +1495,13 @@ end multi:setDomainName("Threads") multi:setDomainName("Globals") local initT = false +local threadCount = 0 function multi:newThread(name,func) - if not func then return end + local func = func + if type(name) == "function" then + func = name + name = "Thread#"..threadCount + end local c={} c.ref={} c.Name=name diff --git a/test.lua b/test.lua index c715d79..f213a9f 100644 --- a/test.lua +++ b/test.lua @@ -1,38 +1,13 @@ ---~ package.path="?/init.lua;?.lua;"..package.path +package.path="?/init.lua;?.lua;"..package.path multi = require("multi") ---~ local GLOBAL,THREAD = require("multi.integration.lanesManager").init() ---~ nGLOBAL = require("multi.integration.networkManager").init() ---~ local a ---~ local clock = os.clock ---~ function sleep(n) -- seconds ---~ local t0 = clock() ---~ while clock() - t0 <= n do end ---~ end ---~ master = multi:newMaster{ ---~ name = "Main", -- the name of the master ---~ noBroadCast = true, -- if using the node manager, set this to true to avoid double connections ---~ managerDetails = {"localhost",12345}, -- the details to connect to the node manager (ip,port) ---~ } ---~ master.OnError(function(name,err) ---~ print(name.." has encountered an error: "..err) ---~ end) ---~ local connlist = {} ---~ multi:newThread("NodeUpdater",function() ---~ while true do ---~ thread.sleep(1) ---~ for i=1,#connlist do ---~ master:execute("TASK_MAN",connlist[i], multi:getTasksDetails()) ---~ end ---~ end ---~ end) ---~ master.OnNodeConnected(function(name) ---~ print("Connected to the node") ---~ table.insert(connlist,name) ---~ end) ---~ multi.OnError(function(...) ---~ print(...) ---~ end) -print("HI!") +local GLOBAL,THREAD = require("multi.integration.lanesManager").init() +nGLOBAL = require("multi.integration.networkManager").init() +multi:newThread(function() + error("Did it work?") +end) +multi.OnError(function(...) + print(...) +end) multi:mainloop{ protect = false, print = true