What is the easiest way to know when a recursive method has finished executing, so that another method may be called?
I have the following code:
[code]
function myMethod() {
// some code
recursiveMethod();
// I want to wait 3 seconds after recursive method has finished before nextMethod() is invoked
// unfortunately, nextMethod() is invoked 3 seconds after recursiveMethod() is first called
timer = setTimeout(‘nextMethod();’, 3000);
}
I am moving an object a distance which is equal to the size of the object being moved (via the recursiveMethod() ), and when it has moved the necessary distance, I want it to stay there for 3 seconds, and then move back to its original location (via nextMethod() ).
Depending on the size of the object, and given a constant speed, the method in setTimeout() may be invoked before the object has moved the necessary distance.
How can I know when recursiveMethod() has finished executing, so that I can invoke nextMethod() (via the setTimeout() method)?