@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.63 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{removeMaybe as t}from"../../../../core/maybe.js";import{throwIfAborted as o,onAbort as e}from"../../../../core/promiseUtils.js";import{DefaultLoadingContext as r}from"../../glTF/DefaultLoadingContext.js";import{load as s}from"./wosrLoader.js";class l{constructor(t){this._gltfLoading=new Map,this._wosrLoading=new Map,this._gltfMemCache=t("gltf-resources",(()=>{})),this._wosrMemCache=t("wosr-resources",(()=>{}))}destroy(){this._gltfLoading.forEach((t=>t.abortController.abort())),this._wosrLoading.forEach((t=>t.abortController.abort())),this._gltfMemCache.destroy(),this._wosrMemCache.destroy()}loadGLTF(t,o,e){const s=e?`gltfPBR:${t}`:`gltf:${t}`,l=this._gltfMemCache.get(s);return null!=l?Promise.resolve(l):a(this._gltfLoading,this._gltfMemCache,s,(async o=>{const{loadGLTF:s}=await import("../../glTF/loader.js");return s(new r(o.streamDataRequester),t,o,e)}),o)}loadWOSR(t,o){const e=`wosr:${t}:${o.disableTextures}`,r=this._wosrMemCache.get(e);return null!=r?Promise.resolve(r):a(this._wosrLoading,this._wosrMemCache,e,(o=>s(t,o)),o)}}async function a(r,s,l,a,i){o(i);const c=e(i,(()=>n(r,l)));let f=r.get(l);if(f)f.refCount++;else{const t=new AbortController;f={refCount:1,abortController:t,promise:a({...i,signal:t.signal})},r.set(l,f)}try{const t=await f.promise;return s.put(l,t),r.delete(l),o(i),t}finally{t(c)}}function n(t,o){const e=t.get(o);if(null!=e){if(--e.refCount>0)return}t.delete(o),null!=e&&e.abortController.abort()}export{l as ObjectResourceCache};