Timer
Object → Timer
The timer object.
Constructor
Timer(interval: ( number | nil ), repetitions_total: ( integer | nil ), name: ( string | nil )): TimerFields
| Name | Type | Description |
|---|---|---|
name | string | The internal name of the timer. Read-only. |
state | Timer.state | The current state of the timer. Read-only. |
interval | number | The delay between repetitions of the timer in seconds. |
repetition_index | integer | The current repetition index of the timer. Read-only. |
repetitions_total | integer | The total amount of repetitions of the timer. |
repetitions_left | integer | The remaining amount of repetitions of the timer. Read-only. |
time_total | number | The total running time of the timer in seconds. Read-only. |
time_remaining | number | The remaining running time of the timer in seconds. Read-only. |
time_elapsed | number | The total elapsed time of the timer in seconds. Read-only. |
time_left | number | The remaining time until the next run of timer callbacks in seconds, or the interval if the timer is stopped. Read-only. |
start_time | number | The start time of the timer in seconds, 0 if the timer is stopped. Read-only. |
Methods
attach | Attaches a handler called on every run of the timer, attaching the same handler twice is a no-op. |
await | Waits for the next run of the timer. |
clear | Removes every handler of the timer, pending handlers of a running call are skipped. |
detach | Detaches a handler previously passed to attach or once. |
isPaused | Checks if the timer object is paused. |
isRunning | Checks if the timer object is running. |
isStopped | Checks if the timer object is stopped. |
once | Attaches a one-shot handler, detached right before the next run of the timer calls it. |
pause | Pauses the timer object. |
resume | Resumes/unpauses the timer object. |
start | Starts/restarts the timer object. |
stop | Stops the timer object. |
#Timer:attach
function Timer:attach(handler: fun( timer: Timer ) | Hook | Event)
Attaches a handler called on every run of the timer, attaching the same handler twice is a no-op.
Handlers run in protected mode, one failing handler is reported and never stops the others.
Parameters
#Timer:await
async function Timer:await(): Timer
Waits for the next run of the timer.
Returns
| Type | Name | Description |
|---|---|---|
Timer | timer |
#Timer:clear
function Timer:clear()
Removes every handler of the timer, pending handlers of a running call are skipped.
#Timer:detach
function Timer:detach(handler: fun( timer: Timer ) | Hook | Event): boolean
Detaches a handler previously passed to attach or once.
Parameters
Returns
| Type | Name | Description |
|---|---|---|
boolean | removed | true if the handler was attached. |
#Timer:isPaused
function Timer:isPaused(): boolean
Checks if the timer object is paused.
Returns
| Type | Name | Description |
|---|---|---|
boolean | is_paused | Returns true if the timer is paused, otherwise false. |
#Timer:isRunning
function Timer:isRunning(): boolean
Checks if the timer object is running.
Returns
| Type | Name | Description |
|---|---|---|
boolean | is_running | Returns true if the timer is running, otherwise false. |
#Timer:isStopped
function Timer:isStopped(): boolean
Checks if the timer object is stopped.
Returns
| Type | Name | Description |
|---|---|---|
boolean | is_stopped | Returns true if the timer is stopped, otherwise false. |
#Timer:once
function Timer:once(handler: fun( timer: Timer ) | Hook | Event)
Attaches a one-shot handler, detached right before the next run of the timer calls it.
Parameters
#Timer:pause
function Timer:pause()
Pauses the timer object.
#Timer:resume
function Timer:resume()
Resumes/unpauses the timer object.
#Timer:start
function Timer:start()
Starts/restarts the timer object.
#Timer:stop
function Timer:stop()
Stops the timer object.