Below given is a workaround for such situations.
Here we takes the idea of while loop + Date time method.
We will create a method which will loop until the required time with time interval in seconds.
One such method is given below.
function sleep(seconds) { var e = new Date().getTime() + (seconds * 1000); while (new Date().getTime() <= e) {} }
This method can be called inside our synchronous method which will work similar to Thread.Sleep and our code will wait the mention seconds till executing the next line
Sample usage
function SampleDelayMaker(){ console.log("Code before delay"); //Waits 60 seconds in this line sleep(60) console.log("Code after delay"); }
No comments:
Post a Comment