Almost done with testing, minor changes

This commit is contained in:
Ryan Ward 2020-02-19 12:32:41 -05:00
parent 1f38b4dcb6
commit 500734d0db
6 changed files with 147 additions and 39 deletions

View File

@ -1,6 +1,6 @@
# multi Version: 14.1.0 System threaded functions (See changes.md)
# multi Version: 14.1.0 System threaded functions and more? (See changes.md for detailed changes)
Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and ill look into it!
Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and I'll look into it!
My multitasking library for lua. It is a pure lua binding, if you ignore the integrations and the love2d compat. If you find any bugs or have any issues, please let me know.
@ -15,13 +15,13 @@ To install copy the multi folder into your environment and you are good to go</b
If you want to use the system threads, then you'll need to install lanes!
**or** use luarocks
Because of a codependency in net libaray, if using the networkmanager you will need to install the net library sepertly
~~Because of a codependency in net libaray, if using the networkmanager you will need to install the net library sepertly~~ The networkManager is currently being reworked. As of right now the net library is not required.
Going forward I will include a Release zip for love2d. I do not know why I haven't done this yet
**The Network Manager rework is currently being worked on and the old version is not included in this version. It will be released in 15.0.0**
```
luarocks install multi
luarocks install lnet
luarocks install lnet (If planning on using the networkManager)
```
Discord
@ -44,7 +44,13 @@ mutli:newThread("Example",function()
print("Hello!")
end
end)
multi:mainloop()
multi:lightloop()
--multi:mainloop()
--[[
while true do
multi:uManager()
end
]]
```
Known Bugs/Issues

View File

@ -12,6 +12,19 @@ Something I plan on doing each version going forward
package.path="?.lua;?/init.lua;?.lua;"..package.path
local multi, thread = require("multi"):init()
GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
serv = multi:newService(function(self,data)
print("Service Uptime: ",self:GetUpTime(),data.test)
end)
serv.OnError(function(...)
print(...)
end)
serv.OnStarted(function(self,data)
print("Started!",self.Type,data)
data.test = "Testing..."
-- self as reference to the object and data is a reference to the datatable that the service has access to
end)
serv:Start()
serv:SetPriority(multi.Priority_Idle)
t = THREAD:newFunction(function(...)
print("This is a system threaded function!",...)
THREAD.sleep(1) -- This is handled within a system thread! Note: this creates a system thread that runs then ends.
@ -95,20 +108,7 @@ end)
print(func("1"))
print(func("Hello"))
print(func("sigh"))
serv = multi:newService(function(self,data)
print("Service Uptime: ",self:GetUpTime(),data.test)
end)
serv.OnError(function(...)
print(...)
end)
serv.OnStarted(function(self,data)
print("Started!",self.Type,data)
data.test = "Testing..."
-- self as reference to the object and data is a reference to the datatable that the service has access to
end)
serv:Start()
serv:SetPriority(multi.Priority_Idle)
multi:mainloop()
multi:lightloop()
```
Going Forward:
---
@ -117,6 +117,7 @@ Going Forward:
Modified:
---
- thread.Priority_* has been moved into THREAD since it pertains to system threads. This only applies to lanes threads!
- 2 new priority options have been added. This addition modified how all options except Core behave. Core is still the highest and Idle is still the lowest!
- multi.Priority_Core — Same: 1
- multi.Priority_Very_High — Added: 4
@ -186,6 +187,7 @@ Removed:
Fixed:
---
- Issue where setting the priority of lanes Threads were not working since we were using the data before one could have a chance to set it. This has been resolved!
- Issue where connections object:conn() was firing based on the existance of a Type field. Now this only fires if the table contains a reference to itself. Otherwise it will connect instead of firing
- Issue where async functions connect wasn't properly triggering when a function returned
- Issue where async functions were not passing arguments properly.

View File

@ -58,6 +58,7 @@ multi.defaultSettings = {
priority = 0,
protect = false,
}
multi.Priority_Core = 1
multi.Priority_Very_High = 4
multi.Priority_High = 16
@ -67,13 +68,7 @@ multi.Priority_Below_Normal = 1024
multi.Priority_Low = 4096
multi.Priority_Very_Low = 16384
multi.Priority_Idle = 65536
thread.Priority_Core = 3
thread.Priority_High = 2
thread.Priority_Above_Normal = 1
thread.Priority_Normal = 0
thread.Priority_Below_Normal = -1
thread.Priority_Low = -2
thread.Priority_Idle = -3
multi.PriorityResolve = {
[1]="Core",
[4]="High",
@ -1829,7 +1824,6 @@ function multi:newService(func) -- Priority managed threads
time = multi:newTimer()
time:Start()
active = true
print("INTERNAL:",Service_Data,active,time,p,scheme)
c:OnStarted(c,Service_Data)
end
local function process()
@ -2058,6 +2052,13 @@ function multi:lightloop()
if not isRunning then
local Loop=self.Mainloop
while true do
if next then
local DD = table.remove(next,1)
while DD do
DD()
DD = table.remove(next,1)
end
end
for _D=#Loop,1,-1 do
if Loop[_D].Active then
self.CID=_D

View File

@ -61,6 +61,7 @@ function THREAD:newFunction(func,holup)
return func(...)
end,...)
return thread:newFunction(function()
thread.hold(function() return t.thread end)
return thread.hold(function()
return t.thread:join(.001)
end)
@ -80,15 +81,21 @@ function multi:newSystemThread(name, func, ...)
c.Type = "sthread"
c.creationTime = os.clock()
c.alive = true
c.priority = thread.Priority_Normal
c.priority = THREAD.Priority_Normal
local args = {...}
c.thread = lanes.gen(table.concat(c.loadString,","),{globals={
THREAD_NAME=name,
THREAD_ID=count,
THREAD = THREAD,
GLOBAL = GLOBAL,
_Console = __ConsoleLinda
},priority=c.priority}, func)(unpack(args))
multi:newThread(function()
print("I am here!")
c.thread = lanes.gen(table.concat(c.loadString,","),
{
globals={
THREAD_NAME=name,
THREAD_ID=count,
THREAD = THREAD,
GLOBAL = GLOBAL,
_Console = __ConsoleLinda
},priority=c.priority}, func)(unpack(args))
thread.kill()
end)
count = count + 1
function c:kill()
self.thread:cancel()

View File

@ -30,6 +30,13 @@ local function getOS()
end
local function INIT(__GlobalLinda,__SleepingLinda)
local THREAD = {}
THREAD.Priority_Core = 3
THREAD.Priority_High = 2
THREAD.Priority_Above_Normal = 1
THREAD.Priority_Normal = 0
THREAD.Priority_Below_Normal = -1
THREAD.Priority_Low = -2
THREAD.Priority_Idle = -3
function THREAD.set(name, val)
__GlobalLinda:set(name, val)
end

View File

@ -1,15 +1,100 @@
package.path="?.lua;?/init.lua;?.lua;"..package.path
local multi, thread = require("multi"):init()
GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
serv = multi:newService(function(self,dat)
print("Service Uptime: ",self:GetUpTime())
serv = multi:newService(function(self,data)
print("Service Uptime: ",self:GetUpTime(),data.test)
end)
serv.OnError(function(...)
print(...)
end)
serv.OnStarted(function(self,data)
print("Started!",self.Type)
print("Started!",self.Type,data)
data.test = "Testing..."
-- self as reference to the object and data is a reference to the datatable that the service has access to
end)
serv:Start()
serv:SetPriority(multi.Priority_Idle)
multi:mainloop()
t = THREAD:newFunction(function(...)
print("This is a system threaded function!",...)
THREAD.sleep(1) -- This is handled within a system thread! Note: this creates a system thread that runs then ends.
return "We done!"
end)
print(t("hehe",1,2,3,true).connect(function(...)
print("connected:",...)
end)) -- The same features that work with thread:newFunction() are here as well
multi.OnLoad(function()
print("Code Loaded!") -- Connect to the load event
end)
t = os.clock()
co = 0
multi.OnExit(function(n)
print("Code Exited: ".. os.clock()-t .." Count: ".. co) -- Lets print when things have ended
end)
test = thread:newFunction(function()
thread.sleep(1) -- Internally this throws a yield call which sends to the scheduler to sleep 1 second for this thread!
return 1,math.random(2,100)
end)
multi:newThread(function()
while true do
thread.skip() -- Even though we have a few metamethods "yielding" I used this as an example of things still happening and counting. It connects to the Code Exited event later on.
co = co + 1
end
end)
-- We can get around the yielding across metamethods by using a threadedFunction
-- For Example
example = {}
setmetatable(example,{
__newindex = function(t,k,v) -- Using a threaded function inside of a normal function
print("Inside metamethod",t,k,v)
local a,b = test().wait() -- This function holds the code and "yields" see comment inside the test function!
-- we should see a 1 seconde delay since the function sleeps for a second than returns
print("We did it!",a,b)
rawset(t,k,v)
-- This means by using a threaded function we can get around the yielding across metamethods.
-- This is useful if you aren't using luajit, or if you using lua in an enviroment that is on version 5.1
-- There is a gotcha however, if using code that was meant to work with another coroutine based scheduler this may not work
end,
__index = thread:newFunction(function(t,k,v) -- Using a threaded function as the metamethod
-- This works by returning a table with a __call metamethod. Will this work? Will lua detect this as a function or a table?
thread.sleep(1)
return "You got a string"
end,true) -- Tell the code to force a wait. We need to do this for metamethods
})
example["test"] = "We set a variable!"
print(example["test"])
print(example.hi)
-- When not in a threaded enviroment at root level we need to tell the code that we are waiting! Alternitavely after the function argument we can pass true to force a wait
c,d = test().wait()
print(c,d)
a,b = 6,7
multi:newThread(function()
a,b = test().wait() -- Will modify Global
print("Waited:",a,b)
--This returns instantly even though the function isn't done!
print("called")
test().connect(function(a,b)
print("Connected:",a,b)
os.exit()
end)
print("Returned")
-- This waits for the returns since we are demanding them
end)
local test = multi:newSystemThreadedJobQueue(4) -- Load up a queue that has 4 running threads
func = test:newFunction("test",function(a) -- register a function on the queue that has an async function feature
test2() -- Call the other registered function on the queue
return a..a
end,true)
func2 = test:newFunction("test2",function(a)
print("ooo")
console = THREAD:getConsole()
console.print("Hello!",true)
end,true) -- When called internally on the job queue the function is a normal sync function and not an async function.
multi:scheduleJob({min = 15, hour = 14},function()
-- This function will be called once everyday at 2:15
-- Using a combination of the values above you are able to schedule a time
end)
print(func("1"))
print(func("Hello"))
print(func("sigh"))
multi:lightloop()