Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

LoopAsync

Deprecated: This function is deprecated in favor of LoopInGameThreadWithDelay. The new function provides cancellation, pause/resume, and state querying capabilities. See the migration guide for details.

Starts a loop that sleeps for the supplied number of milliseconds and stops when the callback returns true.

Parameters

#TypeInformation
1integerThe number of milliseconds to sleep
2functionThe callback function

Example

LoopAsync(1000, function()
    print("Hello World!")
    return false -- Loops forever
end)
-- Use LoopInGameThreadWithDelay for better control
local loopHandle
loopHandle = LoopInGameThreadWithDelay(1000, function()
    print("Hello World!")
    -- Can cancel from anywhere using the handle
    if shouldStop then
        CancelDelayedAction(loopHandle)
    end
end)

-- Benefits:
-- Cancel anytime: CancelDelayedAction(loopHandle)
-- Pause: PauseDelayedAction(loopHandle)
-- Resume: UnpauseDelayedAction(loopHandle)
-- Check state: IsDelayedActionActive(loopHandle)