Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing all the timeouts/intervals in javascript?

I'm writing an application that utilizes JavaScript timeouts and intervals to update the page. Is there a way to see how many intervals are setup? I want to make sure that I'm not accidentally going to kill the browser by having hundreds of intervals setup.

Is this even an issue?

like image 556
Omar Kooheji Avatar asked May 13 '09 15:05

Omar Kooheji


People also ask

What does clearTimeout do in JavaScript?

The global clearTimeout() method cancels a timeout previously established by calling setTimeout() .

What is JavaScript interval?

In JavaScript, a block of code can be executed in specified time intervals. These time intervals are called timing events. There are two methods for executing code at specific intervals.

What does clearTimeout return?

Category: Control. Clears an existing timer by passing in the numeric value returned by setTimeout(). Sometimes you need to clear a timeout timer before it executes. clearTimeout() uses the value returned by the setTimeout(function, milliseconds) function.

Does JavaScript have a timer function?

There are two timer functions in JavaScript: setTimeout() and setInterval() . The following section will show you how to create timers to delay code execution as well as how to perform one or more actions repeatedly using these functions in JavaScript.


1 Answers

I don't think there is a way to enumerate active timers, but you could override window.setTimeout and window.clearTimeout and replace them with your own implementations which do some tracking and then call the originals.

window.originalSetTimeout = window.setTimeout; window.originalClearTimeout = window.clearTimeout; window.activeTimers = 0;  window.setTimeout = function(func, delay) {     window.activeTimers++;     return window.originalSetTimeout(func, delay); };  window.clearTimeout = function(timerID) {     window.activeTimers--;     window.originalClearTimeout(timerID); }; 

Of course, you might not always call clearTimeout, but this would at least give you some way to track what is happening at runtime.

like image 197
Paul Dixon Avatar answered Sep 25 '22 06:09

Paul Dixon