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: use promises in callbacks + cleanup #1160

Merged
merged 5 commits into from
Jan 8, 2025

Conversation

Z3rio
Copy link
Contributor

@Z3rio Z3rio commented Jan 6, 2025

Description

This PR adds the usage of promises in our callbacks. Meaning we can now trigger callbacks in this manner:

local response = QBCore.Functions.TriggerCallback("CALLBACK NAME", 123, "test value")

Without loosing compatibility with the old format:

QBCore.Functions.TriggerCallback("CALLBACK NAME", function(response)

end, 123, "test value")

This also introduces the QBCore.Shared.IsFunction function, to check whether a value is a function OR a funcref!

Only thing I'm a bit unsure about here, would be the fact that functions become funcrefs, which cant be checked via type(), as they return table instead of function. The solution here is a bit hacky, but the only real "good" way would be the PR fivem and add some kind of function to check whether a value is a funcref or not.

Checklist

  • I have personally loaded this code into an updated qbcore project and checked all of its functionality.
  • My code fits the style guidelines.
  • My PR fits the contribution guidelines.

@Z3rio
Copy link
Contributor Author

Z3rio commented Jan 6, 2025

This has been partially tested by me. Any feedback will be greatly appreciated.
Especially any idea on how to better recognize funcrefs

This has now also been tested in-game by me.

@GhzGarage GhzGarage merged commit 8f9d482 into qbcore-framework:main Jan 8, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants