In javascript, there is no such thing as a sleep timer. This is not a nocturnal alarm clock, but a programming function that will stop the code from running for the time set in it. Since javascript doesn’t provide this you have to use setTimeout or this method to create a sleep timer.
This code was written by Marcel of http://www.nodebeginner.org/ He’s a smart guy and I recommend you buy his book on node if you want some great info on node (not to mention the excellent tutorial on the same site. Here is the code:
|
1 2 3 4 5 6 |
function sleep(ms){ var startTime = new Date().getTime(); while(new Date().getTime() < startTime + ms); } sleep(10000); //10000 = 10 seconds, in milliseconds. |