Click to See Complete Forum and Search --> : SetTimeout issue


unknown_striker
04-20-2003, 08:27 AM
Hi,

I have a function that calls itself using setTimeout('function1', 100) 90 times. Within this function, if a certain condition is true it calls another function which also has a setTimeout('function2' 200), I want this one to run 6 times, but while it is running the main looped function carries on executing. I want the main function to stop until function2 has run through it's 6 times.

Anyone have any ideas?

Cheers,
C

DrDaMour
04-20-2003, 11:44 AM
if you're trying to get the MAIN loop to suspend until all the other parts are done, dave's code is a good start


but you need two globa variables firststatus = false
and secondstatus = false

then in your main loop after you call function 1 put a

whie(!firststatus && !secondstatus){
}

now all you need to do is in dave's functions set the sentinels to true (meaning complete)


if (some condition is true) {
secondstatus = false;
secondFunction();
}
if (counter1 < 90) {
setTimeout("firstFunction()",100);
}
else {
firststatus = true;
}



if (counter2 < 6) {
secondstatus=false;
setTimeout("secondFunction()",200);
}
else{
secondstatus=true;
}


that shoudl work in most cases, but of course if you're calling a bunch of functions2's and they stop at weird intervals, it may fail. You'd have to work on security

DrDaMour
04-20-2003, 02:11 PM
I reread what he was talking about, and i was wrong, sorry. I was thinking he wanted the main loop (i'm thinking c here) when he was talking about function1 loop (but said main).