JavaScript Sleep() 2

I found an article Implementing Wait in JavaScript, wrote by Josef Betancourt


This is his example


function Pause(duration, busy){
this.duration= duration * 1000;
this.busywork = null;
this.runner = 0;
if (arguments.length == 2) {
this.busywork = busy;
}
this.pause(this.duration);
}

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



to use


function showme(progIndex){
window.status= "progress: " + progIndex;
}
var p = new Pause(5, showme);



visit Implementing Wait in JavaScript page.

Comments

Popular posts from this blog

Wowza 4.0.1 (Wowza Streaming Engine) Released!

Charles, Java Web Debugging Proxy