how to remove expired timers from active timer table

hello developers

i am facing problem with timers i am storing all active timers in table called

activeTimersTable = {} ;
i am inserting all the initiated timers on it so i can pause them cancel them and resume them

but the problem is there any method to check whether the timer is still or expired ???

so i can cancel all the inactive or expired timers and nil them
with respect …
[import]uid: 74537 topic_id: 18434 reply_id: 318434[/import]

An onComplete listener could be handy for this, if each timer nils itself on Completion, or what have you. Example;

[lua]function cancelTimer()
timer.cancel(timer1)
timer1 = nil
print (timer1)
end

local function test ()
print “test”
onComplete = cancelTimer()
end
timer1 = timer.performWithDelay(1000, test, 1)[/lua]

It wouldn’t have to cancel and nil either, it could set a flag or the like.

Peach :slight_smile: [import]uid: 52491 topic_id: 18434 reply_id: 70772[/import]

thank you @peach for this idea but what if timer is start for more than one time also not endless timer

timer1 = timer.performWithDelay(1000, test, 4)

how to capture the onComplete Event for the last iteration
thanks in advance [import]uid: 74537 topic_id: 18434 reply_id: 70775[/import]

You could do something like this;

[lua]local timer1ran = 0

local function cancelTimer()
timer.cancel(timer1)
timer1 = nil
print (timer1)
end

local function test ()
timer1ran = timer1ran + 1
print “test”
if timer1ran == 4 then
onComplete = cancelTimer()
end
end
timer1 = timer.performWithDelay(1000, test, 4)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 18434 reply_id: 70805[/import]