/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{ReentrantObjectPool as e}from"../../core/ReentrantObjectPool.js";import{afterDispatch as t,isValueInUse as r,scheduleDispatch as o}from"../../core/accessorSupport/watch.js";class s{constructor(r,o){this._owner=o,this._properties={},this._afterDispatchHandle=null;for(const t in r){const o=r[t],s=new e(o,void 0,void 0,2,2);this._properties[t]={pool:s,acquired:[]}}this._afterDispatchHandle=t(()=>this._release())}destroy(){this._afterDispatchHandle&&(this._afterDispatchHandle.remove(),this._afterDispatchHandle=null);for(const e in this._properties){const t=this._properties[e];for(const e of t.acquired)r(e)||t.pool.release(e);t.pool.destroy(),t.pool=null,t.acquired=null}this._properties=null,this._owner=null}get(e){const t=this._owner._get(e),r=this._properties[e];let s=r.pool.acquire();for(r.acquired.push(s);s===t;)s=r.pool.acquire(),r.acquired.push(s);return o(),s}_release(){for(const e in this._properties){const t=this._properties[e];let o=0;for(const e of t.acquired)r(e)?t.acquired[o++]=e:t.pool.release(e);t.acquired.length=o}}}export{s as PropertiesPool};
