Addressing requested changes: pcall replace, errorMessage validation before loop, throwing actual error as formattedErrorMessage

This commit is contained in:
zykem#0643
2024-12-15 15:31:40 +01:00
parent c32c41d718
commit b6e82bd93d
+7 -11
View File
@@ -189,18 +189,16 @@ ESX.Await = function(conditionFunc, errorMessage, timeout)
error('Condition Function should be a function reference.')
end
-- since errorMessage is optional, we only validate it if the user provided it.
if errorMessage then
ESX.AssertType(errorMessage, 'string', 'errorMessage should be a string.')
end
local startTime = GetGameTimer()
local prefix = ('[%s] -> '):format(GetInvokingResource())
while GetGameTimer() - startTime < timeout do
local success, result = pcall(conditionFunc)
if not success then
local conditionErrorMessage = ('%s Error while calling conditionFunc! Result: %s'):format(prefix, result)
print(conditionErrorMessage)
local elapsedTime = GetGameTimer() - startTime
return false, elapsedTime
end
local result = conditionFunc()
if result then
local elapsedTime = GetGameTimer() - startTime
@@ -211,10 +209,8 @@ ESX.Await = function(conditionFunc, errorMessage, timeout)
end
if errorMessage then
ESX.AssertType(errorMessage, 'string', 'errorMessage should be a string.')
local formattedErrorMessage = ('%s %s'):format(prefix, errorMessage)
print(formattedErrorMessage)
error(formattedErrorMessage)
end
return false, timeout