mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
refactor(imports/callback): response varargs
Trying to have scrt compatible responses gets weird when using msgpack.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user