Module hilbish.timers
timeout and interval API
Introduction#
If you ever want to run a piece of code on a timed interval, or want to wait a few seconds, you don't have to rely on timing tricks, as Hilbish has a timer API to set intervals and timeouts.
These are the simple functions hilbish.interval and hilbish.timeout (doc
accessible with doc hilbish, or Module hilbish on the Website).
An example of usage:
lua
local t = hilbish.timers.create(hilbish.timers.TIMEOUT, 5000, function()
print 'hello!'
end)
t:start()
print(t.running) // true
Functions#
hilbish.timers.create(type, time, callback) -> @Timer: Creates a timer that runs based on the specifiedtime.hilbish.timers.get(id) -> @Timer: Retrieves a timer via its ID.hilbish.timers.wait(): Waits for all timers to finish.
Static module fields#
INTERVAL: Constant for an interval timer typeTIMEOUT: Constant for a timeout timer type
timers.create#
hilbish.timers.create(type, time, callback) -> @Timer
Creates a timer that runs based on the specified time.
Parameters#
number type
What kind of timer to create, can either be hilbish.timers.INTERVAL or hilbish.timers.TIMEOUT
number time
The amount of time the function should run in milliseconds.
function callback
The function to run for the timer.
timers.get#
hilbish.timers.get(id) -> @Timer
Retrieves a timer via its ID.
Parameters#
number id
timers.wait#
hilbish.timers.wait()
Waits for all timers to finish.
Parameters#
This function has no parameters.
Types#
Timer#
The Job type describes a Hilbish timer. ## Object Properties
type: What type of timer it isrunning: If the timer is runningduration: The duration in milliseconds that the timer will run
Methods#
start()#
Starts a timer.
stop()#
Stops a timer.