Sleep or wait process on javascript thread
Actually there is no Thread.sleep method on javascript that work on Threading. Moreover there is no true threading in javascript. So everybody that want to deal with threading need to emulate it. In this article i would like to show you some method that emulate sleep method for waiting on a process. Each of this method has each own disadvantage, so you need to choose which is suitable for your case.
First method is sleep using javascript loop. This is first method that come to my mind when emulate sleep method on javascript. We wait for the process by checking the time in the loop.
function wait(millisecond) { var date = new Date(); var current_date = null; do { current_date = new Date(); } while(current_date-date < millisecond) } // do something wait(1000); // wait 1000 millisecond // do something