From the reference libraryRedM

autodoc_shared_functions

jo_libs/modules/waiter/autodoc/autodoc_shared_functions.md

autodoc_shared_functions

JO Functions > jo.waiter.exec()

Execute a function repeatedly until a condition is met or a timeout occurs. <br>

JO Functions > jo.waiter.exec() > Syntax

jo.waiter.exec(condition, executable, loopSpeed, maxDuration)

JO Functions > jo.waiter.exec() > Parameters

condition : function

The condition to stop the loop

executable : function <BadgeOptional />

Function to execute after each test

loopSpeed : integer <BadgeOptional />

The wait between each test in ms <br> default:0

maxDuration : integer <BadgeOptional />

The max duration to wait in ms <br> default:5000

JO Functions > jo.waiter.exec() > Return Value

Type : boolean

True if the condition was met, false if timeout occurred

JO Functions > jo.waiter.exec() > Example

local i = 1

local condition = function() return i > 100 end
local executable = function() i+=1 print(i) end
local loopSpeed = 100
local maxDuration = 1000
local success = jo.waiter.exec(condition, executable, loopSpeed, maxDuration)
print('Is a success:', success)
-- Expected output:
-- 2
-- 3
-- ..
-- 10
-- Is a success: false
Back to documentation