I think thats all thats needed

This commit is contained in:
2018-07-25 12:13:06 -04:00
parent dce6ea201e
commit 88dbb867a7
10 changed files with 454 additions and 19 deletions
+54
View File
@@ -0,0 +1,54 @@
-- set up the package
package.path="?/init.lua;?.lua;"..package.path
-- Import the libraries
multi = require("multi")
local GLOBAL, THREAD = require("multi.integration.lanesManager").init()
nGLOBAL = require("multi.integration.networkManager").init()
-- Act as a master node
master = multi:newMaster{
name = "Main", -- the name of the master
--noBroadCast = true, -- if using the node manager, set this to true to save on some cpu cycles
--managerDetails = {"localhost",12345}, -- the details to connect to the node manager (ip,port)
}
-- Send to all the nodes that are connected to the master
master.OnError(function(name,err)
print(name.." has encountered an error: "..err)
end)
master.OnNodeConnected(function(name)
print("Lets Go!")
master:newNetworkThread("Thread",function(node) -- spawn a network thread on a node that can execute code and return date
local print = node:getConsole().print -- it is important to define things as local... another thing i could do is fenv to make sure all masters work in a protectd isolated enviroment
multi:newTLoop(function()
print("Yo whats up man!")
error("doing a test")
end,1)
end)
master:execute("RemoteTest",name,1,2,3) -- calls a predefined or registered global method on a node
multi:newThread("waiter",function()
print("Hello!",name)
while true do
thread.sleep(2)
master:pushTo(name,"This is a test 2")
if master.connections["NODE_"..name]==nil then
thread.kill()
end
end
end)
end)
multi:newThread("some-test",function()
local dat = master:pop()
while true do
thread.skip(10)
if dat then
print(dat)
end
dat = master:pop()
end
end,"NODE_TESTNODE")
-- Starting the multitasker
settings = {
priority = 0, -- 0, 1 or 2
protect = true,
}
multi:threadloop(settings)
--multi:mainloop(settings)
+37
View File
@@ -0,0 +1,37 @@
package.path="?/init.lua;?.lua;"..package.path
multi = require("multi")
local GLOBAL, THREAD = require("multi.integration.lanesManager").init()
nGLOBAL = require("multi.integration.networkManager").init()
node = multi:newNode{
crossTalk = false, -- default value, allows nodes to talk to eachother. WIP NOT READY YET!
allowRemoteRegistering = true, -- allows you to register functions from the master on the node, default is false
name = nil, --"TESTNODE", -- default value is nil, if nil a random name is generated. Naming nodes are important if you assign each node on a network with a different task
--noBroadCast = true, -- if using the node manager, set this to true to save on some cpu cycles
--managerDetails = {"localhost",12345}, -- connects to the node manager if one exists
}
function RemoteTest(a,b,c) -- a function that we will be executing remotely
--print("Yes I work!",a,b,c)
multi:newThread("waiter",function()
print("Hello!")
while true do
thread.sleep(2)
node:pushTo("Main","This is a test")
end
end)
end
multi:newThread("some-test",function()
local dat = node:pop()
while true do
thread.skip(10)
if dat then
print(dat)
end
dat = node:pop()
end
end,"NODE_TESTNODE")
settings = {
priority = 0, -- 1 or 2
stopOnError = true,
protect = true, -- if something goes wrong we will crash hard, but the speed gain is good
}
multi:mainloop(settings)
+12
View File
@@ -0,0 +1,12 @@
package.path="?/init.lua;?.lua;"..package.path
multi = require("multi")
local GLOBAL, THREAD = require("multi.integration.lanesManager").init()
nGLOBAL = require("multi.integration.networkManager").init()
multi:nodeManager(12345) -- Host a node manager on port: 12345
print("Node Manager Running...")
settings = {
priority = 0, -- 1 or 2
protect = false,
}
multi:mainloop(settings)
-- Thats all you need to run the node manager, everything else is done automatically