mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(waitFor): use GetGameTimer to timeout callbacks
Corrected error message output to ms. Resolves #518.
This commit is contained in:
@@ -10,31 +10,21 @@ function lib.waitFor(cb, errMessage, timeout)
|
||||
|
||||
if value ~= nil then return value end
|
||||
|
||||
|
||||
if timeout or timeout == nil then
|
||||
if type(timeout) ~= 'number' then timeout = 1000 end
|
||||
|
||||
if IsDuplicityVersion() then
|
||||
timeout /= 50;
|
||||
else
|
||||
timeout -= GetFrameTime() * 1000;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local start = GetGameTimer()
|
||||
local i = 0
|
||||
local start = timeout and GetGameTimer()
|
||||
|
||||
while value == nil do
|
||||
if timeout then
|
||||
i += 1
|
||||
Wait(0)
|
||||
|
||||
if i > timeout then
|
||||
return error(('%s (waited %.1fms)'):format(errMessage or 'failed to resolve callback', (GetGameTimer() - start) / 1000), 2)
|
||||
end
|
||||
local elapsed = timeout and GetGameTimer() - start
|
||||
|
||||
if elapsed and elapsed > timeout then
|
||||
return error(('%s (waited %.1fms)'):format(errMessage or 'failed to resolve callback', elapsed), 2)
|
||||
end
|
||||
|
||||
Wait(0)
|
||||
value = cb()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user