refactor(imports/callback): response varargs

Trying to have scrt compatible responses gets weird when using
msgpack.
This commit is contained in:
Linden
2022-12-11 12:39:40 +11:00
parent c141d011d1
commit 124a5f15ba
2 changed files with 12 additions and 10 deletions

View File

@@ -43,15 +43,16 @@ local function triggerServerCallback(_, event, delay, cb, ...)
---@type promise | false
local promise = not cb and promise.new()
events[key] = function(response)
events[key] = function(response, ...)
response = { response, ... }
events[key] = nil
if promise then
return promise:resolve(response and { msgpack.unpack(response) } or {})
return promise:resolve(response)
end
if cb and response then
cb(msgpack.unpack(response))
if cb then
cb(table.unpack(response))
end
end
@@ -81,7 +82,7 @@ local function callbackResponse(success, result, ...)
return false
end
return msgpack.pack(result, ...)
return result, ...
end
local pcall = pcall

View File

@@ -24,15 +24,16 @@ local function triggerClientCallback(_, event, playerId, cb, ...)
---@type promise | false
local promise = not cb and promise.new()
events[key] = function(response)
events[key] = function(response, ...)
response = { response, ... }
events[key] = nil
if promise then
return promise:resolve(response and { msgpack.unpack(response) } or {})
return promise:resolve(response)
end
if cb and response then
cb(msgpack.unpack(response))
if cb then
cb(table.unpack(response))
end
end
@@ -62,7 +63,7 @@ local function callbackResponse(success, result, ...)
return false
end
return msgpack.pack(result, ...)
return result, ...
end
local pcall = pcall