From 2a47de9fd849ba6e03b14255a3ccc3c8d90cef50 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Sun, 20 Nov 2022 12:17:55 -0500 Subject: [PATCH] Added thread.chain(...) --- README.md | 8 +++++--- docs/changes.md | 9 ++++++++- init.lua | 7 +++++++ tests/runtests.lua | 14 +++++++------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d53e19c..753e2d3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -# Multi Version: 15.3.0 Connecting the dots +# Multi Version: 15.3.0 A world of Connections **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! @@ -8,7 +10,7 @@ My multitasking library for lua. It is a pure lua binding, with exceptions of th
-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) ---
diff --git a/docs/changes.md b/docs/changes.md index d9e6631..01f3019 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -83,6 +83,13 @@ multi:mainloop() 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(). - `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}` - 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:[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.` diff --git a/init.lua b/init.lua index 33e77c3..88c2ba9 100644 --- a/init.lua +++ b/init.lua @@ -1122,6 +1122,13 @@ local function conn_test(conn) end end +function thread.chain(...) + local args = select("#") + for i=1,#args do + thread.hold(select(i,...)) + end +end + function thread.hold(n,opt) thread._Requests() local opt = opt or {} diff --git a/tests/runtests.lua b/tests/runtests.lua index 1640e05..ae8b098 100644 --- a/tests/runtests.lua +++ b/tests/runtests.lua @@ -78,7 +78,7 @@ runTest = thread:newFunction(function() thread.pushStatus(a,count) if a == count then break end end - return "Done" + return "Done", true, math.random(1,10000) end) local ret = func(10) local ret2 = func(15) @@ -103,14 +103,14 @@ runTest = thread:newFunction(function() s3 = math.ceil((part/whole)*1000)/10 end) - ret.OnReturn(function() - print("Done 1") + ret.OnReturn(function(...) + print("Done 1",...) end) - ret2.OnReturn(function() - print("Done 2") + ret2.OnReturn(function(...) + print("Done 2",...) end) - ret3.OnReturn(function() - print("Done 3") + ret3.OnReturn(function(...) + print("Done 3",...) end) local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn)