UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 1.65 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{hasRunningElapsedTimer as t}from"./capabilities/DisjointTimerQuery.js";function e(t,e){const u=t.capabilities.disjointTimerQuery;return null==u?null:new r(u,e)}class r{constructor(t,e){this._timer=t,this._queryPool=new Array,this._queryResults=new Map,this._currentQuery=null,e.forEach((t=>{const e=this._timer.createQuery(),r=this._timer.createQuery();this._queryPool.push(e,r),this._queryResults.set(t,null)}))}start(){t||(this._currentQuery=this._queryPool.pop(),null!=this._currentQuery&&(this._timer.disjoint(),this._timer.beginTimeElapsed(this._currentQuery)))}stop(t){if(this._timer.disjoint()||null==this._currentQuery||!this._queryResults.has(t))return this.abort(),null;this._timer.endTimeElapsed();const e=this._queryResults.get(t);if(null==e)return this._queryResults.set(t,this._currentQuery),this._currentQuery=null,null;if(!this._timer.resultAvailable(e))return this._queryPool.unshift(this._currentQuery),this._currentQuery=null,null;const r=this._timer.getResult(e)/1e6;return this._queryPool.unshift(e),this._queryResults.set(t,this._currentQuery),this._currentQuery=null,r}abort(){null!=this._currentQuery&&(this._timer.deleteQuery(this._currentQuery),this._queryPool.unshift(this._timer.createQuery()),this._currentQuery=null)}dispose(){null!=this._currentQuery&&this._timer.deleteQuery(this._currentQuery),this._queryPool.forEach((t=>{this._timer.deleteQuery(t)})),this._queryResults.forEach((t=>{null!=t&&this._timer.deleteQuery(t)}))}}export{e as createElapsedTimerPool};