Skip to content

Waiter Shared โ€‹

The Waiter module provides timing utilities to handle code execution with timeout conditions. It's particularly useful when you need to wait for specific conditions to be met before proceeding with code execution.

JO Functions โ€‹

jo.waiter.exec() โ€‹

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

Syntax โ€‹

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

Parameters โ€‹

condition : function

The condition to stop the loop

executable : function Optional

Function to execute after each test

loopSpeed : integer Optional

The wait between each test in ms
default:0

maxDuration : integer Optional

The max duration to wait in ms
default:5000

Return Value โ€‹

Type : boolean

True if the condition was met, false if timeout occurred

Example โ€‹

lua
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

Last updated: