// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/layers/vectorTiles/core/workers/workers","require exports dojo/promise/all dojo/has ../promiseUtils ./Connection ./DedicatedConnection ./JobProxy".split(" "),function(k,d,l,p,y,z,A,q){function r(){if(m)return m;for(var a=[],b=function(b){var c=q.create(f,b);a.push(c);c.then(function(a){e[b]=a})},c=0;c<h;c++)b(c);return m=l(a).then(function(){return!0})}function t(){if(n)return n;for(var a=[],b=function(b){var c=h+b;b=q.create(f,c);a.push(b);b.then(function(a){e[c]=a})},c=0;c<u;c++)b(c);
return n=l(a).then(function(){return!0})}function B(a,b,c){var d=b.id;if(c)return e[b.workerId].openConnection(a,d);b=[];for(c=0;c<e.length;c++)b.push(e[c].openConnection(a,d));return l(b)}function C(a){var b=v++;a=new d.Connection(a,b);f.set(b,a);return a}function D(a){var b=v++,c=h+w++;w%=u;a=new d.DedicatedConnection(a,b,c);f.set(b,a);return a}Object.defineProperty(d,"__esModule",{value:!0});d.Connection=z;d.DedicatedConnection=A;k=(navigator||{}).hardwareConcurrency||2;var h=p("esri-workers-debug")?
1:Math.max(1,Math.ceil(k/2)),u=p("esri-workers-debug")?1:Math.max(1,Math.floor(k/2)),w=0,e=[],x=0,v=0,f=new Map;d.initialize=function(){r();t()};d.open=function(a,b,c){void 0===c&&(c=!1);return(c?t():r()).then(function(d){var e;e=c?D(a):C(a);return B(b,e,c).then(function(){return e}).otherwise(function(a){return y.reject(a)})})};d.terminate=function(){for(var a=0;a<e.length;a++)e[a]&&e[a].terminate();e.length=0;f.clear()};d.closeConnection=function(a){if(a){if(f.has(a.id))f["delete"](a.id);if(a instanceof
d.DedicatedConnection)e[a.workerId].closeConnection(a.id);else for(var b=0;b<h;b++)e[b]&&e[b].closeConnection(a.id)}};d.invoke=function(a,b,c,d,f){var g=null;d&&(g=d.id);null===g&&(e.some(function(a,b){return b<h&&!a.hasOutgoingJobs()?(g=a.index,!0):!1})||(g=x=(x+1)%h));a=e[g].invoke(a,b,c,f);d&&(d.id=g);return a};d.broadcast=function(a,b,c,d){for(var f=[],g=0;g<h;g++)f.push(e[g].invoke(a,b,c,d));return f};var m,n});