View Single Post
01-01-15, 10:36 AM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Torhal View Post
They're not.
They're not what? Implemented in Lua? Yes they are. Inefficient? Creating new tables (with metatables, even) and new functions for every repeating timer seems pretty inefficient to me, when it's trivial to do "repeat X times and stop" or "cancel this repeating timer" yourself without that overhead.

Code:
local n = 5
local function Update()
     -- stuff
     n = n - 1
     if n > 0 then C_Timer.After(5, Update) end
end
C_Timer.After(5, Update)
Code:
local stop
local function Update()
     if stop then return end
     -- stuff
     C_Timer.After(5, Update)
end
C_Timer.After(5, Update)
-- then in some event handler or wherever:
stop = true
If you're writing an arena macro, sure, go ahead and use them to save space. If you're writing an addon, I just don't see any compelling argument in favor of using them.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote