Potential race condition with timers

Allow me to give an example:

myTimer1 :Timer = new Timer(500);
myTimer2 :Timer = new Timer(1000);

myTimer1.addEventListener(“timer”, TimerFunctionOne);


function TimerFunctionOne()
//do some operation here

function TimerFunctionTwo()
//do some operation here

Now for the tricky bit. Suppose you want this in a class, and you want the ability to pause the class. I can add states to the class which describe what it is doing at the moment, and then stop the relevant timers. However, I can’t seem to find a way to avoid the race condition where the pause function on the object is called just as one of the functions have been called through the timer, and then starts a timer again.

I can add an “if (!paused)” to the timer starters in TimerFunctionOne/Two, but that still leaves a theoretical hole (although small).

So, any thoughts on this?