Timer pause and resume doesn't work well

 Hi everyone.

 I got a problem with timer.pause and timer.resume.

At first, I wanted timer has its pause all and resume all like transition, so I overwrote some apis:

local tableTagTimer = {} local tableIdTimer = {} local typeof = typeof local pairs = pairs local oldPerformWithDelay = timer.performWithDelay local newPerformWithDelay = function(time,func,loop,tag) local id local loopCount = 0 loop = loop or 1 local newFunc = function() if loop ~= 0 then loopCount = loopCount + 1 if loopCount == loop then tableIdTimer[id] = nil end end func() end id = oldPerformWithDelay(time,newFunc,loop) if tag~= nil then if typeof(tag) == "string" then if not tableTagTimer[tag] then tableTagTimer[tag] = {} end table.insert(tableTagTimer[tag],id) elseif typeof(tag) == "boolean" and tag == true then return id end end tableIdTimer[id] = true return id end rawset(timer,"performWithDelay",newPerformWithDelay) local oldCancel = timer.cancel local newCancel = function(id) if id then if typeof(id) == "string" then local temp = tableTagTimer[id] if temp then for i = 1,#temp do oldCancel(temp[i]) end end tableTagTimer[id] = {} else oldCancel(id) end tableIdTimer[id] = nil else for key,\_ in pairs(tableIdTimer) do oldCancel(key) end tableIdTimer = {} tableTagTimer = {} end end rawset(timer,"cancel",newCancel) local oldPause = timer.pause local newPause = function(id) if id then return oldPause(id) else for key,\_ in pairs(tableIdTimer) do oldPause(key) end return end end rawset(timer,"pause",newPause) local oldResume = timer.resume local newResume = function(id) if id then return oldResume(id) else print("Resume all timer -----") for key,\_ in pairs(tableIdTimer) do oldResume(key) end return end end rawset(timer,"resume",newResume)

 I think It runs perfectly, at least when I check with some timers. 

 The problem come when I use them with a large project. A lot of timers, pause, resume v.v.v.

And here is the problem:

When I need to pause my game, I pause all the timers. After doing something, I resume all. And some timers look like they’re still pausing. They don’t run when their times come. And surprisingly, they continue running after another timer runs. Let me make it clear

 I have two timers: A and B. A is timer with 500ms, B is timer with 2000ms. I created them with the same time, and pause all timers after 300ms. I did something, then resume all timers. And I see A is pausing, It doesn’t run when time is 200ms after resuming. But when time goes to 1700ms after pausing, B runs. Surprisingly, A runs at the same time.

 I did a lot of checkings, but still couldn’t find out the reason. I made myself timer like that and the problem gone:

M.addTimer = function(time,func,loop) local objTimer = {} objTimer.duration = time objTimer.loop = loop or 1 objTimer.index = 0 objTimer.timeRun = getTimer() + objTimer.duration objTimer.callback = func M.tableTimers[#M.tableTimers + 1] = objTimer return objTimer end M.updateTimer = function(event) local numTimers = #M.tableTimers for i = numTimers,1,-1 do local objTimer = M.tableTimers[i] if objTimer.needRemove then table.remove(M.tableTimers,i) else if currentTime \>= objTimer.timeRun then objTimer.callback() objTimer.index = objTimer.index + 1 if objTimer.index == objTimer.loop then table.remove(M.tableTimers,i) end end end end end Runtime:addEventListener("enterFrame",M.updateTimer)

 My project is too large so I can’t post it all here.

 Summary:

 - I create myself functions to pause and resume all timer

 - When using those functions with a lot of timer, it has a problem that some timers delay their run time. It seems like they wait for other timers awake them.

 - I create myself timer to debug and see no problem.

 I really think that Corona Timer Library has a problem. Sorry that I couldn’t create a simple sample to show it :frowning:

 Thanks for reading. And sorry for my bad English