Merge branch 'v16.0.0' of https://github.com/rayaman/multi into v16.0.0

This commit is contained in:
Ryan Ward 2023-10-28 17:57:29 -04:00
commit e7ff234cef
2 changed files with 34 additions and 0 deletions

View File

@ -367,6 +367,25 @@ Added
return cn return cn
end end
``` ```
- Connection objects can be divided, function / connection
This is a mix between the behavior between mod and concat, where the original connection can forward it's events to the new one as well as do a check like concat can. View it's implementation below:
```lua
__div = function(obj1, obj2) -- /
local cn = self:newConnection()
local ref
if type(obj1) == "function" and type(obj2) == "table" then
obj2(function(...)
local args = {obj1(...)}
if args[1] then
cn:Fire(multi.unpack(args))
end
end)
else
multi.error("Invalid divide! ", type(obj1), type(obj2)," Expected function/connection(table)")
end
return cn
end
```
- Connection objects can now be concatenated with functions, not each other. For example: - Connection objects can now be concatenated with functions, not each other. For example:
```lua ```lua
multi, thread = require("multi"):init{print=true,findopt=true} multi, thread = require("multi"):init{print=true,findopt=true}

View File

@ -225,6 +225,21 @@ function multi:newConnection(protect,func,kill)
end end
return cn return cn
end, end,
__div = function(obj1, obj2) -- /
local cn = self:newConnection()
local ref
if type(obj1) == "function" and type(obj2) == "table" then
obj2(function(...)
local args = {obj1(...)}
if args[1] then
cn:Fire(multi.unpack(args))
end
end)
else
multi.error("Invalid divide!", type(obj1), type(obj2),"Expected function/connection(table)")
end
return cn
end,
__concat = function(obj1, obj2) -- .. __concat = function(obj1, obj2) -- ..
local cn = self:newConnection() local cn = self:newConnection()
local ref local ref