@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.08 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as t}from"../../chunks/tslib.es6.js";import s from"../../request.js";import"../../core/has.js";import{strict as e}from"../../core/jsonMap.js";import{createAbortError as r}from"../../core/promiseUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{enumeration as i}from"../../core/accessorSupport/decorators/enumeration.js";import{subclass as a}from"../../core/accessorSupport/decorators/subclass.js";import c from"../../rest/networks/support/TraceResult.js";const m=e()({Pending:"job-waiting",InProgress:"job-executing",Completed:"job-succeeded"});let n=class extends c{constructor(t){super(t),this.statusUrl=null,this.status=null,this.submissionTime=null,this.lastUpdatedTime=null,this._timer=void 0}destroy(){clearInterval(this._timer)}async checkJobStatus(t){const e={...t,query:{f:"json"}},{data:r}=await s(this.statusUrl,e),o=r.traceResults?{...r.traceResults,...r}:r;return this.read(o),this}async waitForJobCompletion(t={}){const{interval:s=1e3,statusCallback:e}=t;return new Promise(((t,o)=>{this._clearTimer();const i=setInterval((()=>{this._timer||o(r()),this.checkJobStatus().then((s=>{const{status:r}=s;switch(this.status=r,r){case"job-succeeded":this._clearTimer(),t(this);break;case"job-waiting":case"job-executing":e&&e(this)}}),(t=>{this._clearTimer(),o(t)}))}),s);this._timer=i}))}_clearTimer(){clearInterval(this._timer),this._timer=void 0}};t([o({type:String,json:{write:!0}})],n.prototype,"statusUrl",void 0),t([i(m)],n.prototype,"status",void 0),t([o({type:Date,json:{type:Number,write:{writer:(t,s)=>{s.submissionTime=t?t.getTime():null}}}})],n.prototype,"submissionTime",void 0),t([o({type:Date,json:{type:Number,write:{writer:(t,s)=>{s.lastUpdatedTime=t?t.getTime():null}}}})],n.prototype,"lastUpdatedTime",void 0),n=t([a("esri.networks.support.TraceJobInfo")],n);const p=n;export{p as default};