Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es_extended) Add ESX.Await function #1540

Merged
merged 5 commits into from
Dec 15, 2024

Conversation

Zykem
Copy link

@Zykem Zykem commented Dec 15, 2024

This PR adds a utility function, ESX.Await, to simplify waiting for a condition without the need for manual loops. It checks a condition repeatedly until it’s met or the timeout is reached.

Example usage:

local networkId = ESX.AwaitServerCallback('spawnVehicle')

local function awaitExistence()
    return NetworkDoesEntityExistWithNetworkId(networkId)
end

-- timeElapsed value in MS
local success, timeElapsed = ESX.Await(awaitExistence, 'Timed out :(', 3000)

-- we can now mess with the vehicle spawned server-side on the client-side

@Zykem Zykem changed the title Add ESX.Await function feat(es_extended) Add ESX.Await function Dec 15, 2024
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
@Zykem Zykem requested a review from Kenshiin13 December 15, 2024 13:37
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
[core]/es_extended/shared/functions.lua Outdated Show resolved Hide resolved
@Kenshiin13
Copy link
Contributor

I will do some testing after the latest requested changes have been implemented and merge this. Thank you!

…before loop, throwing actual error as formattedErrorMessage
@Zykem Zykem requested a review from Kenshiin13 December 15, 2024 14:33
Kenshiin13
Kenshiin13 previously approved these changes Dec 15, 2024
Copy link
Contributor

@Kenshiin13 Kenshiin13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Kenshiin13 Kenshiin13 merged commit 778cc0a into esx-framework:dev Dec 15, 2024
1 check passed
@Zykem Zykem deleted the await-func branch December 16, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for Next Update
Development

Successfully merging this pull request may close these issues.

3 participants