Fixed multiplying connections together

This commit is contained in:
Ryan Ward 2022-11-07 10:01:22 -05:00
parent d6d4934a7e
commit 0d3de6e31d
2 changed files with 20 additions and 15 deletions

View File

@ -157,18 +157,18 @@ function multi:newConnection(protect,func,kill)
end, end,
__mul = function(c1,c2) -- And __mul = function(c1,c2) -- And
local cn = multi:newConnection() local cn = multi:newConnection()
if not c1.__hasInstances then if c1.__hasInstances == nil then
cn.__hasInstances = 2 cn.__hasInstances = {2}
cn.__count = {0} cn.__count = {0}
else else
cn.__hasInstances = c1.__hasInstances + 1 cn.__hasInstances = c1.__hasInstances
cn.__hasInstances[1] = cn.__hasInstances[1] + 1
cn.__count = c1.__count cn.__count = c1.__count
end end
c1(function(...) c1(function(...)
cn.__count[1] = cn.__count[1] + 1 cn.__count[1] = cn.__count[1] + 1
print(cn.__count[1], cn.__hasInstances) if cn.__count[1] == cn.__hasInstances[1] then
if cn.__count[1] == cn.__hasInstances then
cn:Fire(...) cn:Fire(...)
cn.__count[1] = 0 cn.__count[1] = 0
end end
@ -176,8 +176,7 @@ function multi:newConnection(protect,func,kill)
c2(function(...) c2(function(...)
cn.__count[1] = cn.__count[1] + 1 cn.__count[1] = cn.__count[1] + 1
print(cn.__count[1], cn.__hasInstances) if cn.__count[1] == cn.__hasInstances[1] then
if cn.__count[1] == cn.__hasInstances then
cn:Fire(...) cn:Fire(...)
cn.__count[1] = 0 cn.__count[1] = 0
end end

View File

@ -114,17 +114,23 @@ runTest = thread:newFunction(function()
end) end)
local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn) local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn)
print("Working!",s1,s2,s3)
if s1 == 100 and s2 == 100 and s3 == 100 then if s1 == 100 and s2 == 100 and s3 == 100 then
print("Threads: Ok") print("Threads: All tests Ok")
else
if s1>0 and s2>0 and s3 > 0 then
print("Thread OnStatus: Ok")
else else
print("Threads OnStatus or thread.hold(conn) Error!") print("Threads OnStatus or thread.hold(conn) Error!")
end end
if timeout then if timeout then
print("Threads or Connection Error!") print("Connection Error!")
else else
print("Connection Test 1: Ok") print("Connection Test 1: Ok")
end end
print("Connection holding Error!")
end
conn1 = proc:newConnection() conn1 = proc:newConnection()
conn2 = proc:newConnection() conn2 = proc:newConnection()
conn3 = proc:newConnection() conn3 = proc:newConnection()