fix(es_extended/client/callback): make sure data is cleaned up

This commit is contained in:
Kasey FItton
2024-11-17 22:59:21 +00:00
parent 32f8e05442
commit faef100add
+9 -12
View File
@@ -21,32 +21,30 @@ function Callbacks:Trigger(event, cb, invoker, ...)
return table.cb return table.cb
end end
function Callbacks:Execute(cb, ...) function Callbacks:Execute(cb, id, ...)
local success, errorString = pcall(cb, ...) local success, errorString = pcall(cb, ...)
if not success then if not success then
print(("[^1ERROR^7] Failed to execute Callback with RequestId: ^5%s^7"):format(self.currentId)) print(("[^1ERROR^7] Failed to execute Callback with RequestId: ^5%s^7"):format(id))
error(errorString) error(errorString)
return return
end end
self.currentId = nil
end end
function Callbacks:ServerRecieve(requestId, invoker, ...) function Callbacks:ServerRecieve(requestId, invoker, ...)
self.currentId = requestId if not self.requests[requestId] then
if not self.requests[self.currentId] then return error(("Server Callback with requestId ^5%s^1 Was Called by ^5%s^1 but does not exist."):format(requestId, invoker))
return error(("Server Callback with requestId ^5%s^1 Was Called by ^5%s^1 but does not exist."):format(self.currentId, invoker))
end end
local callback = self.requests[self.currentId] local callback = self.requests[requestId]
self.requests[requestId] = nil
if callback.await then if callback.await then
callback.cb:resolve({...}) callback.cb:resolve({...})
else else
self:Execute(callback.cb, ...) self:Execute(callback.cb, requestId, ...)
end end
self.requests[requestId] = nil
end end
function Callbacks:Register(name, cb) function Callbacks:Register(name, cb)
@@ -54,7 +52,6 @@ function Callbacks:Register(name, cb)
end end
function Callbacks:ClientRecieve(eventName, requestId, invoker, ...) function Callbacks:ClientRecieve(eventName, requestId, invoker, ...)
self.currentId = requestId
if not self.storage[eventName] then if not self.storage[eventName] then
return error(("Client Callback with requestId ^5%s^1 Was Called by ^5%s^1 but does not exist."):format(eventName, invoker)) return error(("Client Callback with requestId ^5%s^1 Was Called by ^5%s^1 but does not exist."):format(eventName, invoker))
@@ -65,7 +62,7 @@ function Callbacks:ClientRecieve(eventName, requestId, invoker, ...)
end end
local callback = self.storage[eventName] local callback = self.storage[eventName]
self:Execute(callback, returnCb, ...) self:Execute(callback, requestId, returnCb, ...)
end end
---@param eventName string ---@param eventName string