Thread Tools Display Modes
07-26-18, 02:46 PM   #1
pcg79
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2018
Posts: 7
[Solved] CTimer.After first trigger is too fast

I've been playing with AceTimer in my app and I saw some weird behavior where the very first timer trigger happens between 3 and 5 seconds too fast. I figured it was my code or AceTimer so I removed everything from my app's OnInitialize and OnEnable functions and then set my code to use CTimer.After directly (which is what AceTimer uses under the covers). So my app now has this:

Code:
local delay = 10

function CTimerFire()
    print("[ " .. date("%X") .. " ] CTimerFired")

    C_Timer.After(delay, CTimerFire)
end

function TestApp:OnEnable()
    C_Timer.After(delay, CTimerFire)

    local nextFire = time() + delay
    print("[ " .. date("%X") .. " ] It should fire in " .. delay .. " seconds (" .. nextFire .. " aka " .. date("%X", nextFire ) .. ")")
end
And I'm still seeing the same thing. Not once has the first event triggered at the correct time. All subsequent events fire at the correct time, though. I've tried with delays as short as 1 second and as long as 120 seconds. I'm wondering if anyone else has seen this or might know what I'm doing wrong or misunderstanding about addons.

https://imgur.com/a/YQKdlmA

Last edited by pcg79 : 08-05-18 at 05:35 AM.
  Reply With Quote
07-26-18, 02:51 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I don't know if this will fix your issue, but you need to make CTimerFire a local function. Giving it a global name is bad.

Last edited by myrroddin : 07-26-18 at 02:51 PM. Reason: missed a word
  Reply With Quote
07-26-18, 03:53 PM   #3
pcg79
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2018
Posts: 7
Originally Posted by myrroddin View Post
I don't know if this will fix your issue, but you need to make CTimerFire a local function. Giving it a global name is bad.
Thanks for the suggestion, myrroddin. Unfortunately, it didn't change anything. I even tried giving it an anonymous function and it was still early.
  Reply With Quote
07-26-18, 03:57 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
What happes if you give it a delay of 1-2 seconds?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-26-18, 04:24 PM   #5
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
I have seen this with C_Timer.After right at logins, but Overachiever's author also noticed this. They found a weird workaround where you wrap the actual delay you want in a zero second delay.

Lua Code:
  1. C_Timer.After(0,function()
  2.     C_Timer.After(5,function()
  3.         -- do stuff
  4.     end)
  5. end)
  Reply With Quote
07-27-18, 02:27 AM   #6
pcg79
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2018
Posts: 7
Originally Posted by Kanegasi View Post
I have seen this with C_Timer.After right at logins, but Overachiever's author also noticed this. They found a weird workaround where you wrap the actual delay you want in a zero second delay.

Lua Code:
  1. C_Timer.After(0,function()
  2.     C_Timer.After(5,function()
  3.         -- do stuff
  4.     end)
  5. end)
That worked. Thank you!
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » CTimer.After first trigger is too fast

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off