This is an example:
function func1()
{
setTimeout(function(){doSomething();}, 3000);
}
for(i=0;i<10;i++)
{
func1();
}
after executing
You are scheduling 10 calls, but the problem is all are getting scheduled for the same time, ie after 3 seconds.
If you want to call them incrementally then you need to increase the delay in each call.
A solution will be is to pass a delay unit value to the func1
like
function func1(i) {
setTimeout(function() {
doSomething();
}, i * 500);//reduced delay for testing
}
for (i = 0; i < 10; i++) {
func1(i + 1);
}
var counter = 0;
function doSomething() {
snippet.log('called: ' + ++counter)
}