mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-11-24 11:58:35 +00:00
refactor(callbacks): remove the cb argument
BREAKING CHANGE: Registered callbacks now return values rather than sending them as a callback. Previously the cb needed to be called to return to the client, now it will happen once the function closes. i.e. cb(string, string, false) -> return string, string, false
This commit is contained in:
1 parent
2084897785
commit
72575c90ee
3 files changed
+14
-17
No files matched your search
@@ -29,8 +29,8 @@ local ServerCallback = table.create(0, 2)
|
||||
ServerCallback.Await = function(resource, event, delay, ...)
|
||||
if callbackTimer(event, delay) then
|
||||
local promise = promise.new()
|
||||
event = RegisterNetEvent(startCallback(resource, event, ...), function(...)
|
||||
promise:resolve({...})
|
||||
event = RegisterNetEvent(startCallback(resource, event, ...), function(response)
|
||||
promise:resolve(response)
|
||||
RemoveEventHandler(event)
|
||||
end)
|
||||
return table.unpack(Citizen.Await(promise))
|
||||
@@ -44,8 +44,8 @@ end
|
||||
--- Sends an event to the server and triggers a callback function once the response is returned.
|
||||
ServerCallback.Async = function(resource, event, delay, cb, ...)
|
||||
if callbackTimer(event, delay) then
|
||||
event = RegisterNetEvent(startCallback(resource, event, ...), function(...)
|
||||
cb(...)
|
||||
event = RegisterNetEvent(startCallback(resource, event, ...), function(response)
|
||||
cb(table.unpack(response))
|
||||
RemoveEventHandler(event)
|
||||
end)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user