class Deferred<T>
package fivem.shared.core
A typed wrapper over FiveM's Lua promises, for turning callback-style APIs into blocking, straight-line code.
function fetchProfile(id:String):Profile {
var deferred = new Deferred<Profile>();
someResource.getProfile(id, profile -> deferred.resolve(profile));
return deferred.await();
}
await() suspends the calling coroutine, not the resource: other threads,
events and the game itself keep running. It is only valid inside a
coroutine — a thread, event handler, command handler or export — which
covers nearly all resource code but not the top level of main().
Resolving twice is ignored, matching promise semantics; the first settlement wins.
Static methods
staticawaitCallback<T>(register:(resolve:T ‑> Void) ‑> Void):T
Adapts a callback-style function into a blocking call.
var rows = Deferred.awaitCallback(resolve -> db.query("...", resolve));Constructor
Variables
Methods
await():T
Blocks the current coroutine until the promise settles, then returns the
resolved value. A rejection is raised as a Lua error, catchable with an
ordinary Haxe try/catch.
awaitWithTimeout(timeoutMs:Int):Null<T>
Blocks until the promise settles or timeoutMs elapses, returning
null on timeout instead of hanging.
The underlying operation is not cancelled — it just stops being waited on, and a late resolution is discarded.