Promises & async: turning callbacks into linear code
Promises turn nested callback spaghetti into code you read top to bottom. Here's the deal: a callback API is one that doesn't return the answer right away, it hands you a function to run later when the answer lands. FiveM is full of them, like PerformHttpRequest, the older async MySQL libraries, and NUI callbacks. Stack three callbacks and your code becomes a pyramid, each result trapped one level deeper than the last. Promises flatten that pyramid. Pair them with Citizen.Await and the code feels synchronous while the server stays free to do other work. This lesson builds the real thing: you wrap PerformHttpRequest in a promise, await it, handle failure with :reject(), and chain three calls in a straight line.
Watch
Keep reading the full lesson
Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.
- Build it
- How it works
- If something went wrong
- What you can do now
- Try it yourself
The remainder of Promises and async is available to FiveM School members.