Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waiting for functions to execute 2

Status
Not open for further replies.

dle46163

IS-IT--Management
Jul 9, 2004
81
US
Hi All,

I have two Javascript functions.. I want to execute the second function after the first function has completed doing its job. The amount of time for the first function will end up being different every time. So I really need the second function to hold off until the first one is done. Any thoughts on how to accomplish this? Maybe some kind of loop until a specific condition is met?

-dle

 
if you call the second function on the last line of the first function it will not call it until it is complete. If you are calling external processes that run without the javascript function waiting for them to end then you'll need to wait for a return from the external process.

this is simply top down structure as scripting technologies lend themselves to. each line is executed in order and there is no way out of that other than trying to mask it with structuring the code in a module form. still goes top down essentially

____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done
 
ok, I understand... I don't think I did a good job of describing the problem the first time. Here's an example of my code:

Note: this section is not located inside a function.

var x=xxx
var y=yyy
run_this_function();
run_that_function();

** wait until run_that_function is complete then continue **

var x=xxx1
var y=yyy1
run_this_function();
run_that_function();

I understand by nature of Javascript that the second half will execute, but is there any clever code that would cause a delay until a condition is met in run_that_function()?





 
There really isn't a clever way but more of a normal way of structuring your code to better have a handle over what fires and when. Create a main function to do you processing and call the secondary functions from there. you can return values from the secondary functions to handle errors and special events better then.

not structuring your code so you control it over it controlling it along with using global variables are bad forms in programming generally. Do your best to structure it in a controlled manner and to not to use global variables. :)

____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top