WaitTimer

This small library provides an easy way to generate timed events.

You can setup a delayed or repeated function call without messing around with a dummy frame and OnUpdate events.

Example:

-- a delayed function call
WaitTimer.Wait(5, function () DEFAULT_CHAT_FRAME:AddMessage("huhu") end)

-- repeated call (single timer)
WaitTimer.Wait(10, function ()
                  DEFAULT_CHAT_FRAME:AddMessage("wake up")
                  return 10
                end,
                 "mytimer") -- NB: "mytimer" must be a unique name
...
WaitTimer.Stop("mytimer")

-- repeated call
id = WaitTimer.Wait(10, function ()
                  DEFAULT_CHAT_FRAME:AddMessage("wake up")
                  return 10
                end)
...
WaitTimer.Stop(id)

-- with user data
function MyTimer(data) DEFAULT_CHAT_FRAME:AddMessage(data) end
WaitTimer.Wait(5, MyTimer, nil, "Hello World")

Setup:

copy theses files to your addon or any subdirectory of it

  • LibStub.lua
  • WaitTimer.lua

Usually people will use a "lib" subdirectory

Add them at the beginning of your .toc file to make sure they get loaded.

Init:

local WaitTimer = LibStub("WaitTimer")

put it at the beginnig of your lua file where you want to use the WaitTimer.

Usage:

timer_id = WaitTimer.Wait(seconds, function, id, data)
  • seconds= how long to wait
  • function= will be called when time is elapsed
    if the function returns a value, this value is used as new wait_time.
  • id= (optional) a fixed timer id If another timer with the same ID exists it will be replaced
  • data= (optional) will be passed to the function call
  • timer_id= id which can be used in the other functions It's equal "id" when it was provided

WaitTimer.Stop(id)
  • stops the timer without calling the function

waittime = WaitTimer.Remaining(id)
  • return remaining seconds or nil
WaitTimer.SetTime(id, delay)
  • reset the wait time
  • if <delay> is ommited the function will be triggert on next update

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Feb 06, 2012
Category
Last update
Oct 16, 2012
Development stage
Release
Language
  • deDE
  • enUS
  • esES
  • frFR
  • jaJP
  • koKR
  • plPL
  • ruRU
  • zhCN
  • zhTW
License
MIT License
Curse link
WaitTimer
Downloads
736
Recent files
  • R: v1.5 for 5.0.1 Oct 16, 2012
  • R: v1.1 for 4.0.2.2440 Mar 04, 2012
  • R: v1.0 for 4.0.2.2440 Feb 06, 2012

Authors