I've been running into a weird problem repeatedly in JavaScript now. I can't seem to delay setInterval
longer.
A small example of what happens:
var loop;
var count;
loop = setInterval(start, 30);
function start() {
//Some code
delay();
//Some more code
}
function delay() {
setTimeout(function () {
count++;
//Animation code
if (count <= 1000) delay();
}, 100);
}
Now what I want to do is, execute 'some code' part, do nothing while the 'animation code' executes, and then execute 'some more code' part.
What is happening is that the 'some more code' part and the delay function is getting executed simultaneously. I have tried clearInterval(loop)
before calling the delay function and restarting it after the delay function completes it's execution, but the 'some more code' seems to get executed once anyways.
How can I get around this problem? Please give a detailed explanation with an example.