Is there any way to stop a setInterval?

289 views
Skip to first unread message

Ray Perkins

unread,
Aug 2, 2018, 10:22:17 AM8/2/18
to DroidScript
I have a recurring ten second interrupt - setInterval( CheckClock, 10000 ); - that I would like to stop. Any way to do this?
setInterval( CheckClock, 0 ); doesn't do it.

BareK

unread,
Aug 2, 2018, 10:51:01 AM8/2/18
to DroidScript
When you use setInterval, it returns an ID which you can use to call clearInterval.
Your code should looks like:

var interval =  setInterval( CheckClock, 10000 );

/* ... */
if( interval )
{
    clearInterval
( interval );
    interval
= null;
}

Ray Perkins

unread,
Aug 2, 2018, 11:17:07 AM8/2/18
to DroidScript
Thanks. My mistake - I was using the function name instead of the handle. Blame my impending senility!

Jared

unread,
Aug 4, 2018, 10:00:23 AM8/4/18
to DroidScript
you can use the setTimeout in Javascript also possibly

https://www.w3schools.com/jsref/met_win_settimeout.asp

Reply all
Reply to author
Forward
0 new messages