@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.66 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import r from"../../../../core/Accessor.js";import{removeUnordered as s}from"../../../../core/arrayUtils.js";import{makeHandle as e}from"../../../../core/handleUtils.js";import{property as o,subclass as n}from"../../../../core/accessorSupport/decorators.js";import{TaskPriority as i}from"../../../support/Scheduler.js";let a=class extends r{constructor(){super(...arguments),this.referenceCount=0,this.callbacks=new Array,this.runIndex=0}get readyToRun(){return this.callbacks.some(t=>t.running)}runTask(t){this._sort();const r=this.callbacks,s={numIndexLoading:0,numNodesLoading:0};for(let e=0;e<r.length&&!t.done;++e)r[e].priority=r[e].runTask(t,s),this.runIndex=e}_sort(){const t=this.callbacks;let r=t.length;for(let s=this.runIndex;s>0;s--){const e=t[s-1];let o=s;for(;o<t.length&&e.priority<=t[o].priority&&(o!==r||e.priority<t[o].priority);)t[o-1]=t[o],o++;t[o-1]=e,r=o-1}this.runIndex=0}add(t){this._sort(),t.priority=1/0,this.callbacks.unshift(t),this.notifyChange("readyToRun")}remove(t){s(this.callbacks,t),this.runIndex=this.callbacks.length,this._sort(),this.notifyChange("readyToRun")}};t([o({readOnly:!0})],a.prototype,"readyToRun",null),a=t([n("esri.views.3d.layers.i3s.I3SFrameTask")],a);class l{constructor(t,r){this.task=t,this.handle=r}}const c=new Map;function h(t,r){let s=c.get(t);if(null==s){const r=new a,e=t.registerTask(i.I3S_CONTROLLER,r);s=new l(r,e),c.set(t,s)}return s.task.add(r),e(()=>{if(null==s)return;s.task.remove(r);s.task.callbacks.length>0||(c.delete(t),s.handle.remove(),s.task.destroy()),s=null})}export{h as addCallback};