From b6e82bd93da1ceece4c70504215d87995a090283 Mon Sep 17 00:00:00 2001 From: zykem#0643 <86602828+Zykem@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:31:40 +0100 Subject: [PATCH] Addressing requested changes: pcall replace, errorMessage validation before loop, throwing actual error as formattedErrorMessage --- [core]/es_extended/shared/functions.lua | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/[core]/es_extended/shared/functions.lua b/[core]/es_extended/shared/functions.lua index e6411222..4b8b4f2d 100644 --- a/[core]/es_extended/shared/functions.lua +++ b/[core]/es_extended/shared/functions.lua @@ -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