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 returnnil
.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. Ifnil
, 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
Last updated