// Append ?raw to the URL of this page to view the raw source (for 
// comments, copyright & licence), or ?pretty for a colorized version.

AsyncQueue=Base.extend({constructor:function(this_){this.this_=this_;this.queue=[];if(window.MochiKit&&window.MochiKit.Async){this.deferred=new MochiKit.Async.Deferred();}else{this.deferred=null;}},next:function(f){this.queue.push(this._next(f));return this;},loop:function(f){return this.loopResult(function(){return f;});},loopResult:function(f){this.queue.push(this._loop(f));return this;},defer:function(o){this.queue.push(this._defer(o));return this;},go:function(){this._advance();return this.deferred;},_next:function(f){var self=this;return function(){f.apply(self.this_,[]);self._advance();};},_loop:function(f){var self=this;return function(){var t=self.this_;var res=f.apply(t);var start=(new Date).getTime();function run(){try{while(true){self._multi_call(res);var now=(new Date).getTime();if(now-start>self.MAX_BLOCK){window.setTimeout(run,self.BREAK_DELAY);start=now;return;}}}catch(e){if(e!==AsyncQueue.StopLoop){throw e;}
self._advance();}};run();};},_multi_call:function(f){var t=this.this_;f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);f.apply(t);},_defer:function(o){var self=this;var a=function(){self._advance();};if(o instanceof MochiKit.Async.Deferred){return function(){o.addCallback(a);};}else{return function(){o.apply(self.this_).addCallback(a);};}},_advance:function(){var q=this.queue;if(q.length){window.setTimeout(q.shift(),this.BREAK_DELAY);}else{if(this.deferred)
this.deferred.callback(this.this_);}},toString:function(){return"[AsyncQueue instance]";},MAX_BLOCK:3000,BREAK_DELAY:1},{StopLoop:{toString:function(){return"[AsyncQueue.StopLoop]";}},stop_loop:function(){throw AsyncQueue.StopLoop;}});