/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","exports","../../chunks/_rollupPluginBabelHelpers","../Error","../has","../promiseUtils","./Connection","./RemoteClient","./WorkerOwner"],(function(e,t,n,r,o,i,l,u,s){"use strict";function c(e){if(e&&e.__esModule)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}let a=o("esri-workers-debug")?1:o("host-browser")?navigator.hardwareConcurrency-1:0;a||(a=o("safari")&&o("mac")||o("trident")?7:2);let f=0;const d=[];function p(){_()}function m(e,t){return y(e,{client:t})}function y(e,t){return h.apply(this,arguments)}function h(){return(h=n._asyncToGenerator((function*(e,t){const n=new l;return yield n.open(e,t),n}))).apply(this,arguments)}function b(e){return g.apply(this,arguments)}function g(){return(g=n._asyncToGenerator((function*(t,n={}){if("string"!=typeof t)throw new r("workers:undefined-module","modulePath is missing");let l=n.strategy||"distributed";if(o("host-webworker")&&!o("esri-workers")&&(l="local"),"local"===l){let r=yield u.loadWorker(t);r||(r=yield new Promise(((n,r)=>e([
/* @vite-ignore */
/* webpackIgnore: true */
t],(e=>n(c(e))),r)))),i.throwIfAborted(n.signal);const o=n.client||r;return y([u.connect(r)],{...n,client:o})}if(yield _(),i.throwIfAborted(n.signal),"dedicated"===l){const e=f++%a;return y([yield d[e].open(t,n)],n)}if(n.maxNumWorkers&&n.maxNumWorkers>0){const e=Math.min(n.maxNumWorkers,a);if(e<a){const r=new Array(e);for(let o=0;o<e;++o){const e=f++%a;r[o]=d[e].open(t,n)}return y(r,n)}}return y(d.map((e=>e.open(t,n))),n)}))).apply(this,arguments)}function w(){P&&(k.abort(),P=null);for(let e=0;e<d.length;e++)d[e]&&d[e].terminate();d.length=0}let k,P=null;function _(){return O.apply(this,arguments)}function O(){return(O=n._asyncToGenerator((function*(){if(P)return P;k=new AbortController;const e=[];for(let t=0;t<a;t++){const n=s.create(t).then((e=>(d[t]=e,e)));e.push(n)}return P=Promise.all(e),P}))).apply(this,arguments)}t.Connection=l,t.RemoteClient=u,t.initialize=p,t.open=b,t.openWithPorts=m,t.terminate=w,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
