UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.89 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as r}from"../../../../chunks/tslib.es6.js";import s from"../../../../core/Accessor.js";import{removeUnordered as t}from"../../../../core/arrayUtils.js";import{makeHandle as e}from"../../../../core/handleUtils.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import{subclass as n}from"../../../../core/accessorSupport/decorators/subclass.js";import{TaskPriority as i}from"../../../support/Scheduler.js";let a=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 o=t;for(;o<r.length&&e.priority<=r[o].priority&&(o!==s||e.priority<r[o].priority);)r[o-1]=r[o],o++;r[o-1]=e,s=o-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([o({readOnly:!0})],a.prototype,"running",null),a=r([n("esri.views.3d.layers.i3s.I3SFrameTask")],a);class l{constructor(r,s){this.task=r,this.handle=s}}const c=new Map;function h(r,s){let t=c.get(r);if(null==t){const s=new a,e=r.registerTask(i.I3S_CONTROLLER,s);t=new l(s,e),c.set(r,t)}return t.task.add(s),e((()=>{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{h as addCallback};