DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Pause Function For JavaScript
http://ourworld.cs.com/tcmits1/javascript/papers/pause/pause.html
<script type = "text/javascript"language = "JavaScript">
/* constructor
duration integer seconds
<optional> function to run while waiting.
*/
function Pause(duration, busy) {
this.duration = duration * 1000;
this.busywork = null;
// function to call while waiting.
this.runner = 0;
if (arguments.length == 2) {
this.busywork = busy;
}
this.pause(this.duration);
}/* Pause class*/
/* pause method
duration: integer in seconds
*/
Pause.prototype.pause = function(duration) {
if ((duration == null) || (duration < 0)) {
return;
}
var later = (new Date()).getTime() + duration;
while (true) {
if ((new Date()).getTime() > later) {
break;
}
this.runner++;
if (this.busywork != null) {
this.busywork(this.runner);
}
}/* while*/
}/*pause method*/
</script>





