/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../core/arrayUtils","../../../support/Scheduler"],(function(t,e,n,r){"use strict";let s=function(){function t(t){this.referenceCount=0,this.callbacks=[],this.runIndex=0,this.handle=t.registerTask(r.TaskPriority.I3S_CONTROLLER,this)}var s=t.prototype;return s.destroy=function(){this.handle&&(this.handle.remove(),this.handle=null)},s.runTask=function(t){this._sort();const e=this.callbacks,n={numIndexLoading:0,numNodesLoading:0};for(let r=0;r<e.length&&!t.done;++r)e[r].priority=e[r].update(t,n),this.runIndex=r},s._sort=function(){const t=this.callbacks;let e=t.length;for(let n=this.runIndex;n>0;n--){const r=t[n-1];let s=n;for(;s<t.length&&r.priority<=t[s].priority&&(s!==e||r.priority<t[s].priority);)t[s-1]=t[s],s++;t[s-1]=r,e=s-1}this.runIndex=0},s.add=function(t){this._sort(),t.priority=1/0,this.callbacks.unshift(t)},s.remove=function(t){n.removeUnordered(this.callbacks,t),this.runIndex=this.callbacks.length,this._sort()},e._createClass(t,[{key:"running",get:function(){for(const t of this.callbacks)if(t.needsUpdate())return!0;return!1}}]),t}();const i=new Map;function o(t,e){let n=i.get(t);return null==n&&(n=new s(t),i.set(t,n)),n.add(e),{remove:()=>{if(null==n)return;n.remove(e);n.callbacks.length>0||(i.delete(t),n.destroy()),n=null}}}t.addTask=o,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
