Globals::waitForAsync

From RAGE Multiplayer Wiki
Revision as of 18:15, 25 December 2024 by Shr0x (talk | contribs) (Created page with "{{ClientsideJsFunction}} {{JSContainer| === Summary === Executes a callback function and resolves a promise when the callback completes, or rejects if the timeout is reached. === Syntax === <syntaxhighlight lang="javascript"> mp.game.waitForAsync(cb, timeout = 60000); </syntaxhighlight> === Required Parameters === * '''cb:''' {{RageType|function}} - The callback function to execute. * '''timeout:''' {{RageType|number}} - Optional. Timeout in milliseconds (default: 600...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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