class Callbacks
package fivem.client.core
Request/response calls between client and server.
FiveM events only travel one way. Callbacks layers a correlation key over
a pair of events so a client can ask the server a question and block on the
answer, and vice versa:
// client
var balance:Int = Callbacks.await("bank:getBalance");
// server (fivem.server.core.Callbacks)
Callbacks.register("bank:getBalance", (source, args) -> accounts.balanceOf(source));
await suspends only the calling coroutine, so it must be called from
inside one — a thread, event handler, command handler or export. The rest
of the resource keeps running while it waits.
A callback is a network round trip. Don't put one in a per-frame loop; cache the answer, or push updates through a state bag instead.
Static methods
staticawait(name:String, args:Rest<Dynamic>):Dynamic
Asks the server and waits for the answer.
Parameters:
timeoutMs | How long to wait before giving up and returning
|
|---|
staticawaitWithTimeout(name:String, timeoutMs:Int, args:Rest<Dynamic>):Dynamic
As await, with an explicit timeout.
staticregister(name:String, handler:(args:Array<Dynamic>) ‑> Dynamic):Void
Registers a handler the server can call.
The handler's return value is sent back as the answer. It runs on a coroutine, so it may block — awaiting another callback or a database query inside one is fine.
staticrequest(name:String, onResult:(result:Dynamic) ‑> Void, args:Rest<Dynamic>):Void
Asks the server without blocking, delivering the answer to onResult.
Use this from code that isn't running on a coroutine, or when the result isn't needed to continue.