updated opt for connections

This commit is contained in:
2026-05-14 22:29:34 -07:00
parent 4a52cd5e14
commit c86413351c
+8 -5
View File
@@ -496,7 +496,8 @@ function multi:newConnection(protect,func,kill)
function c:Unlock(conn) function c:Unlock(conn)
if conn and conn.lock then if conn and conn.lock then
for i = 1, #fast do local n = #fast
for i = 1, n do
if conn.lock == fast[i] then if conn.lock == fast[i] then
fast[i] = fast[conn.ref] fast[i] = fast[conn.ref]
return self return self
@@ -512,12 +513,13 @@ function multi:newConnection(protect,func,kill)
function c:Fire(...) function c:Fire(...)
if lock then return end if lock then return end
local kills = {} local kills = {}
for i=1,#fast do local n = #fast
for i=1, n do
local suc, err = pcall(fast[i], ...) local suc, err = pcall(fast[i], ...)
if not suc then if not suc then
multi.error(err) multi.error(err)
end end
if kill then if kill and n > 0 then
table.insert(kills,i) table.insert(kills,i)
processor:newTask(function() processor:newTask(function()
for _, k in pairs(kills) do for _, k in pairs(kills) do
@@ -592,11 +594,12 @@ function multi:newConnection(protect,func,kill)
__CurrentConnectionThread = nil __CurrentConnectionThread = nil
end end
end end
local ref = multi.randomString(24)
table.insert(fast, func) table.insert(fast, func)
if name then if name then
fast[name] = func fast[name] = func
else else
fast["Conn_"..multi.randomString(12)] = func fast["Conn_"..ref:sub(1, 12)] = func
end end
local temp = {fast = true} local temp = {fast = true}
setmetatable(temp,{ setmetatable(temp,{
@@ -616,7 +619,7 @@ function multi:newConnection(protect,func,kill)
rawset(t,k,v) rawset(t,k,v)
end, end,
}) })
temp.ref = multi.randomString(24) temp.ref = ref
fast[temp.ref] = func fast[temp.ref] = func
temp.name = name temp.name = name
temp.link = self temp.link = self