Appearance
AceTimer-3.0
AceTimer-3.0 provides a central facility for registering timers.
AceTimer supports one-shot timers and repeating timers. All timers are stored in an efficient data structure that allows easy dispatching and fast rescheduling. Timers can be registered or canceled at any time, even from within a running timer, without conflict or large overhead.
AceTimer is currently limited to firing timers at a frequency of 0.01s as this is what the WoW timer API restricts us to.
All :Schedule functions will return a handle to the current timer, which you will need to store if you need to cancel the timer you just registered.
API Reference
Embed
method#
lua
AceTimer:Embed(target)Copies AceTimer's methods onto target so you can call them on it directly. See The :Embed method.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
target | table | Target object to embed AceTimer in. |
Returns
| Type | Description |
|---|---|
table | The target object that was embedded. |
ScheduleTimer
method#
lua
AceTimer:ScheduleTimer(func, delay, ...)Schedule a new one-shot timer.
The timer will fire once in delay seconds, unless canceled before.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
func | function | methodname | Callback function for the timer pulse (funcref or method name). | |
delay | number | Delay for the timer, in seconds. | |
... | any | An optional, unlimited amount of arguments to pass to the callback function. |
Returns
| Type | Description |
|---|---|
string | The timer handle, used to cancel the timer with :CancelTimer. |
Example
lua
function MyAddon:OnEnable()
self:ScheduleTimer("TimerFeedback", 5)
end
function MyAddon:TimerFeedback()
print("5 seconds passed")
endScheduleRepeatingTimer
method#
lua
AceTimer:ScheduleRepeatingTimer(func, delay, ...)Schedule a repeating timer.
The timer will fire every delay seconds, until canceled.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
func | function | methodname | Callback function for the timer pulse (funcref or method name). | |
delay | number | Delay for the timer, in seconds. | |
... | any | An optional, unlimited amount of arguments to pass to the callback function. |
Returns
| Type | Description |
|---|---|
string | The timer handle, used to cancel the timer with :CancelTimer. |
Example
lua
function MyAddon:OnEnable()
-- store the handle so the timer can be cancelled later
self.pulseTimer = self:ScheduleRepeatingTimer("Pulse", 5)
end
function MyAddon:Pulse()
-- runs every 5 seconds until cancelled
endCancelTimer
method#
lua
AceTimer:CancelTimer(id)Cancels a timer with the given id, registered by the same addon object as used for :ScheduleTimer.
Both one-shot and repeating timers can be canceled with this function, as long as the id is valid and the timer has not fired yet or was canceled before.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | The id of the timer, as returned by :ScheduleTimer or :ScheduleRepeatingTimer. |
Returns
| Type | Description |
|---|---|
boolean | true if the timer was successfully cancelled, false if the id was invalid or the timer already fired/was cancelled. |
Example
lua
function MyAddon:OnEnable()
self.timer = self:ScheduleRepeatingTimer("Pulse", 1)
end
function MyAddon:StopPulse()
self:CancelTimer(self.timer)
endCancelAllTimers
method#
lua
AceTimer:CancelAllTimers()Cancels all timers registered to the current addon object (self).
TimeLeft
method#
lua
AceTimer:TimeLeft(id)Returns the time left for a timer with the given id, registered by the current addon object (self).
This function will return 0 when the id is invalid.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | The id of the timer, as returned by :ScheduleTimer or :ScheduleRepeatingTimer. |
Returns
| Type | Description |
|---|---|
number | The time left on the timer. |
