Right now the only way to wait for some time in a lua script is to do a busy wait:
function sleep(a)
local sec = tonumber(os.clock() + a);
while(os.clock() < sec) do
end
end
However this will lock up the entire program until the sleep function has returned.
If a Timer class or similar would be added, or simply a callback that is called every n seconds it would open up some new ways scripts can interact with the user. In my case I was trying to implement a timeout to WebSocket so that if it hasn't managed to connect yet after 3 seconds it would stop trying to connect and update the UI to allow the user to manually restart the connection process.
API could look something like this:
local timer = Timer{delay=1.0, onTick=function() print("Tick Tock") end, repeat=true}
timer:start()
Right now the only way to wait for some time in a lua script is to do a busy wait:
However this will lock up the entire program until the sleep function has returned.
If a Timer class or similar would be added, or simply a callback that is called every n seconds it would open up some new ways scripts can interact with the user. In my case I was trying to implement a timeout to WebSocket so that if it hasn't managed to connect yet after 3 seconds it would stop trying to connect and update the UI to allow the user to manually restart the connection process.
API could look something like this: