WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   CTimer.After first trigger is too fast (https://www.wowinterface.com/forums/showthread.php?t=56450)

pcg79 07-26-18 02:46 PM

[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

myrroddin 07-26-18 02:51 PM

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.

pcg79 07-26-18 03:53 PM

Quote:

Originally Posted by myrroddin (Post 329033)
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.

Fizzlemizz 07-26-18 03:57 PM

What happes if you give it a delay of 1-2 seconds?

Kanegasi 07-26-18 04:24 PM

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)

pcg79 07-27-18 02:27 AM

Quote:

Originally Posted by Kanegasi (Post 329038)
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!


All times are GMT -6. The time now is 04:37 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI