/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{cyrb53 as e}from"../../../../../../core/string.js";import{discardUrlIfHasUrlHash as t}from"../../urlUtils.js";import{AResourceProxy as r}from"../../shaderGraph/techniques/mesh/AResourceProxy.js";class s extends r{constructor(e){super(),this._fetcher=e,this._controller=new AbortController,this._pendingRequests=new Map,this._resourceIdToResource=new Map}destroy(){this._controller.abort()}get _abortOptions(){return{signal:this._controller.signal}}enqueueRequest(r){const s=t(r.resource),o=e(JSON.stringify(s));return this._pendingRequests.has(o)||this._pendingRequests.set(o,r),o}async fetchEnqueuedResources(){const e=Array.from(this._pendingRequests.entries()),t=e.map(e=>e[1]);if(0===t.length)return;const r=await this._fetcher.fetch(t,this._abortOptions);for(let s=0;s<r.length;s++){const t=e[s][0];this._resourceIdToResource.set(t,r[s])}this._pendingRequests.clear()}async fetchResourceImmediate(e){const t=await this._fetcher.fetch([e]);if(1!==t.length)throw new Error("FeaturePipelineResourceProxy: failed to fetch resources");return t[0]}async fetchDictionaryResourceImmediate(e){const t=await this._fetcher.fetchDictionary([e]);if(1!==t.length)throw new Error("FeaturePipelineResourceProxy: failed to fetch dictionary resources");return t[0]}async fetchMeshResourceImmediate(e){const t=await this._fetcher.fetchMesh([e]),[r]=t;if(!r)throw new Error("FeaturePipelineResourceProxy: failed to fetch mesh resources");return r}getResource(e){return this._resourceIdToResource.get(e)}}export{s as ResourceProxy};
