Cleaning up code, fixing bugs (Almost ready for release)

This commit is contained in:
Ryan Ward 2021-11-30 20:11:20 -05:00
parent efa30e30cc
commit a7ba146a64
4 changed files with 97 additions and 85 deletions

View File

@ -3,7 +3,7 @@
- thread.hold has been updated to allow all variants to work as well as some new features. Check the changelog or documentation for more info. - thread.hold has been updated to allow all variants to work as well as some new features. Check the changelog or documentation for more info.
- multi:newProccesor() Creates a process that acts like the multi namespace that can be managed independently from the mainloop. - multi:newProccesor() Creates a process that acts like the multi namespace that can be managed independently from the mainloop.
Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and I'll look into it! Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and someone will look into it!
My multitasking library for lua. It is a pure lua binding, with exceptions of the integrations and the love2d compat. If you find any bugs or have any issues, please [let me know](https://github.com/rayaman/multi/issues) and I'll look into it!. My multitasking library for lua. It is a pure lua binding, with exceptions of the integrations and the love2d compat. If you find any bugs or have any issues, please [let me know](https://github.com/rayaman/multi/issues) and I'll look into it!.
@ -33,6 +33,7 @@ Planned features/TODO
Usage: [Check out the documentation for more info](https://github.com/rayaman/multi/blob/master/Documentation.md)</br> Usage: [Check out the documentation for more info](https://github.com/rayaman/multi/blob/master/Documentation.md)</br>
----- -----
```lua ```lua
package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
local multi, thread = require("multi"):init() local multi, thread = require("multi"):init()

View File

@ -364,12 +364,14 @@ Fixed:
--- ---
- Threaded functions not returning multiple values [Ref. Issue](https://github.com/rayaman/multi/issues/21) - Threaded functions not returning multiple values [Ref. Issue](https://github.com/rayaman/multi/issues/21)
- Priority Lists not containing Very_High and Very_Low from previous update
- All functions that should have chaining now do, reminder all functions that don't return any data return a reference to itself to allow chaining of method calls.
ToDo ToDo
--- ---
- N/A - Work on network parallelism (I really want to make this, but time and getting it right is proving much more difficult)
- Work on QOL changes to allow cleaner code like [this](#connection-can-now-be-added-together)
# Update 15.0.0 - The art of faking it # Update 15.0.0 - The art of faking it
Full Update Showcase Full Update Showcase

View File

@ -21,11 +21,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
]] ]]
local multi = {} local multi = {}
local mainloopActive = false local mainloopActive = false
local isRunning = false local isRunning = false
local clock = os.clock local clock = os.clock
local thread = {} local thread = {}
if not _G["$multi"] then if not _G["$multi"] then
_G["$multi"] = {multi=multi,thread=thread} _G["$multi"] = {multi=multi,thread=thread}
end end
@ -61,16 +63,18 @@ multi.Priority_Idle = 65536
multi.PriorityResolve = { multi.PriorityResolve = {
[1]="Core", [1]="Core",
[4]="High", [4]="Very High",
[16]="Above Normal", [16]="High",
[64]="Normal", [64]="Above Normal",
[256]="Below Normal", [256]="Normal",
[1024]="Low", [1024]="Below Normal",
[4096]="Idle", [4096]="Low",
[16384]="Very Low"
[65536]="Idle",
} }
multi.PStep = 1 multi.PStep = 1
multi.PList = {multi.Priority_Core,multi.Priority_High,multi.Priority_Above_Normal,multi.Priority_Normal,multi.Priority_Below_Normal,multi.Priority_Low,multi.Priority_Idle} multi.PList = {multi.Priority_Core,multi.Priority_Very_High,multi.Priority_High,multi.Priority_Above_Normal,multi.Priority_Normal,multi.Priority_Below_Normal,multi.Priority_Low,multi.Priority_Very_Low,multi.Priority_Idle}
multi.PriorityTick=1 multi.PriorityTick=1
multi.Priority=multi.Priority_High multi.Priority=multi.Priority_High
multi.threshold=256 multi.threshold=256
@ -314,6 +318,7 @@ end
function multi:create(ref) function multi:create(ref)
multi.OnObjectCreated:Fire(ref,self) multi.OnObjectCreated:Fire(ref,self)
return self
end end
function multi:setName(name) function multi:setName(name)
@ -429,9 +434,11 @@ function multi:newConnection(protect,func,kill)
end end
function c:Lock() function c:Lock()
c.lock = true c.lock = true
return self
end end
function c:Unlock() function c:Unlock()
c.lock = false c.lock = false
return self
end end
function c:Fire(...) function c:Fire(...)
local ret={} local ret={}
@ -1582,6 +1589,7 @@ function multi:newService(func) -- Priority managed threads
th:kill() th:kill()
c.Stop() c.Stop()
multi.setType(c,multi.DestroyedObj) multi.setType(c,multi.DestroyedObj)
return c
end end
function c:SetScheme(n) function c:SetScheme(n)
if type(self)=="number" then n = self end if type(self)=="number" then n = self end
@ -1630,6 +1638,7 @@ function multi:newService(func) -- Priority managed threads
if type(self)=="number" then pri = self end if type(self)=="number" then pri = self end
p = pri p = pri
c.SetScheme(scheme) c.SetScheme(scheme)
return c
end end
multi.create(multi,c) multi.create(multi,c)
return c return c
@ -2212,10 +2221,12 @@ function multi:setPriority(s)
self.defPriority = self.Priority self.defPriority = self.Priority
self.PrioritySet = true self.PrioritySet = true
end end
return self
end end
function multi:ResetPriority() function multi:ResetPriority()
self.Priority = self.defPriority self.Priority = self.defPriority
return self
end end
function os.getOS() function os.getOS()
@ -2348,6 +2359,7 @@ function multi:reallocate(o,n)
self.Parent=o self.Parent=o
table.insert(o.Mainloop,n,self) table.insert(o.Mainloop,n,self)
self.Active=true self.Active=true
return self
end end
function multi.timer(func,...) function multi.timer(func,...)
@ -2366,6 +2378,7 @@ end
function multi:FreeMainEvent() function multi:FreeMainEvent()
self.func={} self.func={}
return self
end end
function multi:connectFinal(func) function multi:connectFinal(func)
@ -2379,6 +2392,7 @@ function multi:connectFinal(func)
multi.print("Warning!!! "..self.Type.." doesn't contain a Final Connection State! Use "..self.Type..":Break(func) to trigger it's final event!") multi.print("Warning!!! "..self.Type.." doesn't contain a Final Connection State! Use "..self.Type..":Break(func) to trigger it's final event!")
self:OnBreak(func) self:OnBreak(func)
end end
return self
end end
if os.getOS()=="windows" then if os.getOS()=="windows" then

145
test.lua
View File

@ -5,7 +5,7 @@ func = thread:newFunction(function(count)
local a = 0 local a = 0
while true do while true do
a = a + 1 a = a + 1
thread.sleep(.1) thread.sleep(.5)
thread.pushStatus(a,count) thread.pushStatus(a,count)
if a == count then break end if a == count then break end
end end
@ -32,87 +32,82 @@ end)
--GLOBAL,THREAD = require("multi.integration.threading"):init() -- Auto detects your environment and uses what's available --GLOBAL,THREAD = require("multi.integration.threading"):init() -- Auto detects your environment and uses what's available
-- func = thread:newFunction(function() func2 = thread:newFunction(function()
-- thread.sleep(3) thread.sleep(3)
-- print("Hello World!") print("Hello World!")
-- return true return true
-- end,true) -- set holdme to true end,true) -- set holdme to true
-- func:holdMe(false) -- reset holdme to false func2:holdMe(false) -- reset holdme to false
-- print("Calling func...") print("Calling func...")
-- print(func()) print(func2())
test = thread:newFunction(function(a,b)
thread.sleep(1)
return a,b
end)
print(test(1,2).connect(function(...)
print(...)
end))
test:Pause()
print(test(1,2).connect(function(...)
print(...)
end))
test:Resume()
print(test(1,2).connect(function(...)
print(...)
end))
test = thread:newFunction(function()
return 1,2,nil,3,4,5,6,7,8,9
end,true)
print(test())
multi:newThread("testing",function()
print("#Test = ",test())
print(thread.hold(function()
print("Hello!")
return false
end,{
interval = 2,
cycles = 3
})) -- End result, 3 attempts within 6 seconds. If still false then timeout
print("held")
end).OnError(function(...)
print(...)
end)
-- test = thread:newFunction(function(a,b) sandbox = multi:newProcessor("Test Processor")
-- thread.sleep(1) sandbox:newTLoop(function()
-- return a,b print("testing...")
-- end) end,1)
-- print(test(1,2).connect(function(...)
-- print(...)
-- end))
-- test:Pause()
-- print(test(1,2).connect(function(...)
-- print(...)
-- end))
-- test:Resume()
-- print(test(1,2).connect(function(...)
-- print(...)
-- end))
-- test = thread:newFunction(function() test2 = multi:newTLoop(function()
-- return 1,2,nil,3,4,5,6,7,8,9 print("testing2...")
-- end,true) end,1)
-- print(test())
-- multi:newThread("testing",function()
-- print("#Test = ",test())
-- print(thread.hold(function()
-- print("Hello!")
-- return false
-- end,{
-- interval = 2,
-- cycles = 3
-- })) -- End result, 3 attempts within 6 seconds. If still false then timeout
-- print("held")
-- end).OnError(function(...)
-- print(...)
-- end)
-- sandbox = multi:newProcessor() sandbox:newThread("Test Thread",function()
-- for i,v in pairs(sandbox.process) do local a = 0
-- print(i,v) while true do
-- end thread.sleep(1)
-- io.read() a = a + 1
-- sandbox:newTLoop(function() print("Thread Test: ".. multi.getCurrentProcess().Name)
-- print("testing...") if a == 10 then
-- end,1) sandbox.Stop()
end
end
end).OnError(function(...)
print(...)
end)
-- test2 = multi:newTLoop(function() multi:newThread("Test Thread",function()
-- print("testing2...") while true do
-- end,1) thread.sleep(1)
print("Thread Test: ".. multi.getCurrentProcess().Name)
end
end).OnError(function(...)
print(...)
end)
-- sandbox:newThread("Test Thread",function() sandbox.Start()
-- local a = 0
-- while true do
-- thread.sleep(1)
-- a = a + 1
-- print("Thread Test: ".. multi.getCurrentProcess().Name)
-- if a == 10 then
-- sandbox.Stop()
-- end
-- end
-- end).OnError(function(...)
-- print(...)
-- end)
-- multi:newThread("Test Thread",function()
-- while true do
-- thread.sleep(1)
-- print("Thread Test: ".. multi.getCurrentProcess().Name)
-- end
-- end).OnError(function(...)
-- print(...)
-- end)
-- sandbox.Start()
multi:mainloop() multi:mainloop()