mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Addressing requested changes: pcall replace, errorMessage validation before loop, throwing actual error as formattedErrorMessage
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user