Globals::waitForAsync

From RAGE Multiplayer Wiki

Client-Side
Function

 JavaScript



JavaScript Syntax


Summary

Executes a callback function and resolves a promise when the callback completes, or rejects if the timeout is reached.

Syntax

mp.game.waitForAsync(cb, timeout = 60000);

Required Parameters

  • cb: function - The callback function to execute.
  • timeout: number - Optional. Timeout in milliseconds (default: 60000).

Return Value

  • 'Promise<bool>' - Resolves to `true` if the callback completes, or `false` if it times out.

Example

mp.game.waitForAsync(() => {
    mp.gui.chat.push("Callback completed!");
}, 10000).then(success => {
    if (success) {
        mp.gui.chat.push("Async operation succeeded.");
    } else {
        mp.gui.chat.push("Async operation timed out.");
    }
});


See Also