UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.67 kB
import{_ as r}from"../../../../chunks/tslib.es6.js";import s from"../../../../core/Accessor.js";import{removeUnordered as t}from"../../../../core/arrayUtils.js";import{property as e}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as n}from"../../../../core/accessorSupport/decorators/subclass.js";import{TaskPriority as o}from"../../../support/Scheduler.js";let i=class extends s{constructor(){super(),this.referenceCount=0,this.callbacks=new Array,this.runIndex=0}get running(){return this.callbacks.some((r=>r.running))}runTask(r){this._sort();const s=this.callbacks,t={numIndexLoading:0,numNodesLoading:0};for(let e=0;e<s.length&&!r.done;++e)s[e].priority=s[e].runTask(r,t),this.runIndex=e}_sort(){const r=this.callbacks;let s=r.length;for(let t=this.runIndex;t>0;t--){const e=r[t-1];let n=t;for(;n<r.length&&e.priority<=r[n].priority&&(n!==s||e.priority<r[n].priority);)r[n-1]=r[n],n++;r[n-1]=e,s=n-1}this.runIndex=0}add(r){this._sort(),r.priority=1/0,this.callbacks.unshift(r),this.notifyChange("running")}remove(r){t(this.callbacks,r),this.runIndex=this.callbacks.length,this._sort(),this.notifyChange("running")}};r([e({readOnly:!0})],i.prototype,"running",null),i=r([n("esri.views.3d.layers.i3s.I3SFrameTask")],i);class a{constructor(r,s){this.task=r,this.handle=s}}const c=new Map;function l(r,s){let t=c.get(r);if(null==t){const s=new i,e=r.registerTask(o.I3S_CONTROLLER,s);t=new a(s,e),c.set(r,t)}return t.task.add(s),{remove:()=>{if(null==t)return;t.task.remove(s);t.task.callbacks.length>0||(c.delete(r),t.handle.remove(),t.task.destroy()),t=null}}}export{l as addCallback};