//>>built
define("dojox/timing/ThreadPool",["./_base"],function(){dojo.experimental("dojox.timing.ThreadPool");var e=dojox.timing;e.threadStates={UNSTARTED:"unstarted",STOPPED:"stopped",PENDING:"pending",RUNNING:"running",SUSPENDED:"suspended",WAITING:"waiting",COMPLETE:"complete",ERROR:"error"};e.threadPriorities={LOWEST:1,BELOWNORMAL:2,NORMAL:3,ABOVENORMAL:4,HIGHEST:5};e.Thread=function(g,k){var a=this;this.state=e.threadStates.UNSTARTED;this.priority=k||e.threadPriorities.NORMAL;this.lastError=null;this.func=
g;this.invoke=function(){a.state=e.threadStates.RUNNING;try{g(this),a.state=e.threadStates.COMPLETE}catch(f){a.lastError=f,a.state=e.threadStates.ERROR}}};e.ThreadPool=new function(g,k){var a=[],f=Array(g+1),h=new dojox.timing.Timer;this.getMaxThreads=function(){return g};this.getAvailableThreads=function(){return g};this.getTickInterval=function(){return k};this.queueUserWorkItem=function(b){b instanceof Function&&(b=new e.Thread(b));for(var d=a.length,c=0;c<a.length;c++)if(a[c].priority<b.priority){d=
c;break}d<a.length?a.splice(d,0,b):a.push(b);return!0};this.removeQueuedUserWorkItem=function(b){if(b instanceof Function){for(var d=-1,c=0;c<a.length;c++)if(a[c].func==b){d=c;break}return-1<d?(a.splice(d,1),!0):!1}d=-1;for(c=0;c<a.length;c++)if(a[c]==b){d=c;break}return-1<d?(a.splice(d,1),!0):!1};this.start=function(){h.start()};this.stop=function(){h.stop()};this.abort=function(){this.stop();for(var b=1;b<f.length;b++)f[b]&&window.clearTimeout(f[b]);for(var d in f[0])this.queueUserWorkItem(d);f[0]=
{}};this.reset=function(){this.abort();a=[]};this.sleep=function(b){h.stop();window.setTimeout(h.start,b)};h.onTick=this.invoke}(16,5E3);return dojox.timing.ThreadPool});