I have 2 scripts
script1 = function() {
// takes very long time
}
script2 = function() {
// takes less time
}
I want to ensure that script2 should run after script1 is complete.
put your script2 to script1. Or for more general solution make script1 function to receive callback function(script2) and call it.
This is the way of many many jquery async functions
script1 = function(callback){
//takes very long time
callback();
}
script2 = function(){
//takes less time
}
...
//call like this
script1(script2);
what I did before is to set a global bool variable and only assign it to true in the end in script1, and in script2, check the variable, if it's not true, use setTimeOut to call itself later. I know it sounds not a good solution but that's what I realized I can do.
script2()from the end ofscript1()?