Preventing Simultaneous Functions

K

kid

I need help with a page i'm coding which has several functions to
dynamically change the display. Everything works fine but the problem
is that I need to have the final function wait for all others to
finish before it resets certain onscreen buttons and then returns.I'm
having trouble implementing this efficiently and would greatly
appreciate any help/comments.
 
T

Thomas 'PointedEars' Lahn

kid said:
I need help with a page i'm coding which has several functions to
dynamically change the display. Everything works fine but the problem
is that I need to have the final function wait for all others to
finish before it resets certain onscreen buttons and then returns.I'm
having trouble implementing this efficiently and would greatly
appreciate any help/comments.

Post *relevant snippets* of your code or the URI
of a test case and we will see what can be done.


PointedEars
 
B

Brian Genisio

kid said:
I need help with a page i'm coding which has several functions to
dynamically change the display. Everything works fine but the problem
is that I need to have the final function wait for all others to
finish before it resets certain onscreen buttons and then returns.I'm
having trouble implementing this efficiently and would greatly
appreciate any help/comments.

Yeah... what Thomas said... except, here is a basic outline of something
you might want to try... untested, but it should help out. If you show
more, we can help more.

First of all, I am assuming you must be using something like setTimeout
on all of your functions to execute. This assumption is based off the
fact that Javascript executes serially in all browsers I know about.
This means that you should know when a script is done, unless you are
setting events (via setTimeout or setInterval).

Ok, making that assumption, think about this:

/////////////////////////////////////////////////////////////////
var func1_done = false;
var func2_done = false;
var func3_done = false;

function func1() {
//... code
func1_done = true;
}

function func2() {
//... do someting
func2_done = true;
}

function func3() {
//... do something
func3_done = true;
}

function checkForDone() {
if( func1_done && func2_done && func3_done )
{
// Do what you need to do... all three are done
}
else
setTimeout("checkForDone()", 500); // check again in 1/2 sec
}
/////////////////////////////////////////////////////////////////

Then, you can run checkForDone, when you want to execute your code. It
will only execute if 1, 2 and 3 are done. If not, it will try again in
half of a second (change this to whatever you think is necessary)

Also, for good programming practices, use an array for the funcN_done
flags, if you have more than three functions to worry about.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top