Samuel's Development, Official Documentation
  • 🎉Welcome
  • 📑Overview
    • Resources
      • Bobcat Weapon Heist
        • Installation Guide
        • Configuration
      • Traphouse Robbery
        • Installation Guide
        • Configuration
      • Pacific Bank Heist
        • Installation Guide
        • Configuration
      • Oxy Run
        • Installation Guide
        • Configuration
      • Dumpster Diving
        • Installation Guide
        • Configuration
        • Log Configuration
      • Warehouse Heist
        • Installation Guide
        • Configuration
      • Oil Rig
        • Installation Guide
        • Configuration
      • Beekeeping
        • Installation Guide
        • Configuration
        • Log Configuration
      • Yacht Robbery
        • Installation Guide
        • Configuration
      • Notify
        • Installation
        • Configuration
      • Cocaine Mission
        • Installation Guide
        • Configuration
      • Advanced Drug Sales
        • Installation Guide
        • Configuration
    • Library
      • Installation & Integration
      • Modules
        • Client
          • Callback
          • StartProgress
          • LoadAnim
          • LoadModel
          • LoadPtfxAsset
          • ShowNotification
          • SendEmail
          • PoliceDispatch
          • StartHack
        • Server
          • Callback
          • Name
          • Money
          • Logger
          • Inventory
          • HasGroup
          • GetPlayer
          • GetPlayers
          • GetPlayerByIdentifier
          • GetIdentifier
          • GetPlayerGender
          • CheckVersion
        • Shared
          • Array
          • Table
          • String
          • Math
          • Locale
            • JSON Example
          • AwaitLoad
          • Framework
  • 📚F.A.Q
    • How do I change Locales?!
    • How to add Police Alerts?!
    • What types of dirty money are supported?
Powered by GitBook
On this page
  • Overview
  • Parameters
  • Returns
  • Usage Example
  1. Overview
  2. Library
  3. Modules
  4. Shared

AwaitLoad

The SD.AwaitLoad function is designed to handle asynchronous waiting scenarios in Lua, where it's necessary to wait for a specific condition to be met before proceeding. This function includes timeout management to avoid infinite loops and ensure responsive code execution.

Overview

Purpose: Waits for a specified condition to be met, returning a value if successful within a given timeout, or throws an error if the timeout expires.

Parameters

  • callback (fun(): T|nil): A callback function that checks the desired condition. This function should return a non-nil value once the condition is met. If the condition is not met, it should return nil.

  • errorMessage (string, optional): The message to display if the timeout is exceeded. Defaults to "Operation timed out".

  • timeoutDuration (number|nil, optional): The maximum duration to wait for the condition to be met, specified in milliseconds. If nil, the default of 1000 milliseconds is used.

Returns

  • (T|nil): Returns the value obtained from the callback function if the condition is met within the specified timeout period. If the timeout is exceeded, it throws an error.

Usage Example

SD.LoadAnim = function(animDict)
    if type(animDict) ~= "string" then error("Animation dictionary identifier must be a string.") end

    if not HasAnimDictLoaded(animDict) then
        RequestAnimDict(animDict)

        -- Use sd.awaitLoad to wait for the animation dictionary to load with a timeout.
        SD.AwaitLoad(function()
            if HasAnimDictLoaded(animDict) then
                return true -- Return true indicating the dictionary is loaded.
            end
        end, ("Failed to load animation dictionary '%s'").format(animDict), 5000) -- 5000 ms timeout.
    end
end

return SD.LoadAnim

PreviousJSON ExampleNextFramework

Last updated 1 year ago

📑