Added thread.chain(...)

This commit is contained in:
Ryan Ward 2022-11-20 12:17:55 -05:00
parent 0d3de6e31d
commit 2a47de9fd8
4 changed files with 27 additions and 11 deletions

View File

@ -1,6 +1,8 @@
# Multi Version: 15.3.0 Connecting the dots # Multi Version: 15.3.0 A world of Connections
**Key Changes** **Key Changes**
- Bug fix - SystemThreadedConnections
- Restructured the directory structure of the repo (Allows for keeping multi as a submodule and being able to require it as is)
- Bug fixes
Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and someone will look into it! Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and someone will look into it!
@ -8,7 +10,7 @@ My multitasking library for lua. It is a pure lua binding, with exceptions of th
</br> </br>
Progress is being made in [v15.3.0](https://github.com/rayaman/multi/tree/v15.3.0) Progress is being made in [v15.4.0](https://github.com/rayaman/multi/tree/v15.4.0)
--- ---
</br> </br>

View File

@ -83,6 +83,13 @@ multi:mainloop()
Added Added
--- ---
- `thread.chain(...)` allows you to chain `thread.hold(FUNCTIONs)` together
```
while true do
thread.chain(hold_function_1, hold_function_2)
end
```
If the first function returns true, it moves on to the next one
- Experimental option to multi settings: `findopt`. When set to `true` it will print out a message when certain pattern are used with this library. For example if an anonymous function is used in thread.hold() within a loop. The library will trigger a message alerting you that this isn't the most performant way to use thread.hold(). - Experimental option to multi settings: `findopt`. When set to `true` it will print out a message when certain pattern are used with this library. For example if an anonymous function is used in thread.hold() within a loop. The library will trigger a message alerting you that this isn't the most performant way to use thread.hold().
- `multi:newSystemThreadedConnection()` - `multi:newSystemThreadedConnection()`
@ -101,7 +108,7 @@ Changed
--- ---
- Internally all `OnError` events are now connected to with multi.print, you must pass `print=true` to the init settings when initializing the multi object. `require("multi"):init{print=true}` - Internally all `OnError` events are now connected to with multi.print, you must pass `print=true` to the init settings when initializing the multi object. `require("multi"):init{print=true}`
- All actors now use fastmode on connections - All actors now use fastmode on connections
- Performance enhancement with processes that are pumped instead of automatically running, by suppressing the creation of an internal loop object that would manage the process - Performance enhancement with processes that are pumped. Instead of automatically running, by suppressing the creation of an internal loop object that would manage the process, we bypass that freeing up memory and adding a bit more speed.
- `Connection:fastMode() or Connection:SetHelper()` now returns a reference to itself - `Connection:fastMode() or Connection:SetHelper()` now returns a reference to itself
- `Connection:[connect, hasConnections, getConnection]` changed to be `Connection:[Connect, HasConnections, getConnections]`. This was done in an attempt to follow a consistent naming scheme. The old methods still will work to prevent old code breaking. - `Connection:[connect, hasConnections, getConnection]` changed to be `Connection:[Connect, HasConnections, getConnections]`. This was done in an attempt to follow a consistent naming scheme. The old methods still will work to prevent old code breaking.
- `Connections when added(+) together now act like 'or', to get the 'and' feature multiply(*) them together.` - `Connections when added(+) together now act like 'or', to get the 'and' feature multiply(*) them together.`

View File

@ -1122,6 +1122,13 @@ local function conn_test(conn)
end end
end end
function thread.chain(...)
local args = select("#")
for i=1,#args do
thread.hold(select(i,...))
end
end
function thread.hold(n,opt) function thread.hold(n,opt)
thread._Requests() thread._Requests()
local opt = opt or {} local opt = opt or {}

View File

@ -78,7 +78,7 @@ runTest = thread:newFunction(function()
thread.pushStatus(a,count) thread.pushStatus(a,count)
if a == count then break end if a == count then break end
end end
return "Done" return "Done", true, math.random(1,10000)
end) end)
local ret = func(10) local ret = func(10)
local ret2 = func(15) local ret2 = func(15)
@ -103,14 +103,14 @@ runTest = thread:newFunction(function()
s3 = math.ceil((part/whole)*1000)/10 s3 = math.ceil((part/whole)*1000)/10
end) end)
ret.OnReturn(function() ret.OnReturn(function(...)
print("Done 1") print("Done 1",...)
end) end)
ret2.OnReturn(function() ret2.OnReturn(function(...)
print("Done 2") print("Done 2",...)
end) end)
ret3.OnReturn(function() ret3.OnReturn(function(...)
print("Done 3") print("Done 3",...)
end) end)
local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn) local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn)