API/LibShefkiTimer-1.0
LibShefkiTimer-1.0 provides a centeral facility for registering timers.
LibShefkiTimer supports one-shot timers and repeating tiemrs. ShefkiTimer is
intended to be a drop in replacement for AceTimer. Tiemrs are implemented using
AnimationGroup frames. This allows the game engine to do all the scheduling
as opposed to a single OnUpdate event handler doing scheduling. Timers
can be registered or canceled at any time, even from within a running
timer, without conflict or large overhead.
ShefkiTimer can fire timers at pretty much any resolution that the game can handle.
In fact it can fire timers at a higher resolution than GetTime() can report time
passing for.
All `:Schedule` functions will return a handle to the timer it registered, which you will need to store if you need to cancel the timer you just registered.
LibShefkiTimer-1.0 can be embeded into your addon, either explicitly by calling
LibShefkiTimer:Embed(MyAddon) or by specifying it as an embeded library in your AceAddon.
All functions will be availalbe on your addon object and can be accesssed directly,
without having to explcitly calling ShefkiTimer itself.
It is recommended to embed ShefkiTimer, otherwise you'll have to specify a custom `self`
on calls you make into ShefkiTimer
ShefkiTimer:CancelAllTimers()
Cancels all timers registered to the current addon object ('self')
ShefkiTimer:CancelTimer(handle, silent)
Cancels a timer with the given handle, registered by same addon object as used for `:ScheduleTimer` Bot one-shot and repeating timers can be canceled wit this function, as long as the `handle` is valid and the timer has not fired yet or was canceled before.
Parameters
- handle
- The handle of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
- silent
- If true, no error is raised if the tiemr handle is invalid (expired or already canceled)
Return value
True if the timer was successfully cancelled.
ShefkiTimer:ScheduleRepeatingTimer(callback, delay, arg)
Schedule a repeating timer.
The timer will fire every `delay` seconds, until canceled.
Parameters
- callback
- Callback function for the timer pulse (funcref or method name).
- delay
- Delay for the timer, in seconds.
- arg
- An optional argument to be passed to the callback function.
Usage
MyAddon = LibStub("AceAddon-3.0"):NewAddon("TimerTest", "LibShefkiTimer-1.0") function MyAddon:OnEnable() self.timerCount = 0 self.testTimer = self:ScheduleRepeatingTimer("TimerFeedback", 5) end function MyAddon:TimerFeedback() self.timerCount = self.timerCount + 1 print(("%d seconds passed"):format(5 * self.timerCount)) -- run 30 seconds in total if self.timerCount == 6 then self:CancelTimer(self.testTimer) end end
ShefkiTimer:ScheduleTimer(callback, delay, arg)
Schedule a new one-shot timer.
The timer will fire once in `delay` seconds, unless canceled before.
Parameters
- callback
- Callback function for the timer pulse (funcref or method name).
- delay
- Delay for the timer, in seconds.
- arg
- An optional argument to be passed to the callback function.
Usage
MyAddon = LibStub("AceAddon-3.0"):NewAddon("TimerTest", "LibShefkiTimer-1.0") function MyAddon:OnEnable() self:ScheduleTimer("TimerFeedback", 5) end function MyAddon:TimerFeedback() print("5 seconds passed") end
ShefkiTimer:TimeLeft(handle)
Returns the time left for a timer with the given handle, registered by the current addon object ('self').
This function will raise a warning when the handle is invalid, but not stop execution.
Parameters
- handle
- The handle of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer`
Return value
The time left on the timer, or false if the handle is invalid.
Comments