Skip to main content
TRACK B·PRODUCTION ENGINEERING·Verified June 2026 · Lua 5.4 · ox_lib 3.x
Learning with an AI assistant?
Copies this lesson plus 2026 ground rules (no lua54 'yes', Cfx.re Portal, correct callback signatures) as a ready-to-paste mentor prompt.

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.

You'll learn
promise.new(), :resolve(), :reject(), Citizen.Await, and the callback-to-promise wrapping pattern
Time
~22 minutes
Prereqs
P1 (oxmysql), P2 (HTTP)
Outcome
You can wrap any callback API as a promise and read three async calls top to bottom instead of nesting them

Watch

RED: async patterns and how the UI ties into them.
BEFORE YOU START

Keep reading the full lesson

Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.

Still ahead in this lesson
  • 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.