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 ---@type promise | false
local promise = not cb and promise.new() local promise = not cb and promise.new()
events[key] = function(response) events[key] = function(response, ...)
response = { response, ... }
events[key] = nil events[key] = nil
if promise then if promise then
return promise:resolve(response and { msgpack.unpack(response) } or {}) return promise:resolve(response)
end end
if cb and response then if cb then
cb(msgpack.unpack(response)) cb(table.unpack(response))
end end
end end
@@ -81,7 +82,7 @@ local function callbackResponse(success, result, ...)
return false return false
end end
return msgpack.pack(result, ...) return result, ...
end end
local pcall = pcall local pcall = pcall

View File

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