views:

65

answers:

2

In one HTML page I have a JavaScript function checkUpdates() that hits the server. I make this function run every 5 seconds with this line:

window.setInterval("checkUpdates()", 5 * 1000);

In Firebug, I put a breakpoint inside the checkUpdates() function. However, after the code execution stops at this breakpoint, pressing "continue" sometimes doesn't do anything. All the JavaScript on my page appears to have stopped.

Does this have something to do with the above line of code? Does the loop that executes checkUpdates() every 5 seconds pause when I am at a breakpoint, or does it continue running in the background? I wonder if waiting longer than the 5-second interval to press "continue" is what causes things to break.

Side note: I am new to Javascript and event-driven programming in general, so I am still a bit fuzzy on a few of the paradigms, such as whether code gets executed sequentially or concurrently. Any pointers to reading material on this would be appreciated.

+1  A: 

Does the loop that executes checkUpdates() every 5 seconds pause when I am at a breakpoint, or does it continue running in the background?

I'm guessing it continues to run.

I wonder if waiting longer than the 5-second interval to press "continue" is what causes things to break.

That was my first guess. It's easy enough to test - try setting the interval to 500 seconds.

Triptych
Thanks Triptych. From testing, does appear to be the issue.
RexE
+1  A: 

Does the loop that executes checkUpdates() every 5 seconds pause when I am at a breakpoint, or does it continue running in the background?

Yes, it does STOP everything!

but soon you click "Continue" or "Play" it will resume and continue to break in the same spot (I'm guessing that you are breaking inside the checkUpdates method.

use the Firebug in order to track this, it is very easy to use.

I just made a simple HTML file so you can see this running

screencast: http://is.gd/Kt9x

code : http://jsbin.com/izazu <-- remember that you can edit adding /edit in front of the url.

balexandre
Wow! Thanks for the screencast, balexandre!
RexE
no problem, glad you like it, hope you can learn from it and improve your way to code/debug :)
balexandre