I’m currently using a loop that repeats itself every few milliseconds in my program. In this loop, it checks for a certain input, and if received, cancels another timeout. Essentially:
if (inputreceived && secondTimerRunning)
{
timerID2.clearTimeout();
secondTimerRunning = false;
}
However, those lines cause my loop to terminate. From what I can tell, it’s because I am trying to clear a Timeout that doesn’t exist. Is there a way to prevent this, or am I using Timeouts wrong?
The syntax for
clearTimeout()is;It is a function which accepts the ID returned by
setTimeout(); i.e. you don’t call it on the ID returned.clearTimeoutwill not error if the value you pass to it is not a valid ID.For more info, see the documentation for
clearTimeout()on MDC.