UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.12 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 s}from"../chunks/tslib.es6.js";import e from"./Accessor.js";import{createResolver as i,createAbortError as r,isAbortError as t}from"./promiseUtils.js";import{subclass as o}from"./accessorSupport/decorators/subclass.js";var l;!function(s){s[s.PENDING=0]="PENDING",s[s.RESOLVED=1]="RESOLVED",s[s.REJECTED=2]="REJECTED"}(l||(l={}));class h{constructor(){this._resolver=i(),this._status=l.PENDING,this._resolvingPromises=[],this._resolver.promise.then((()=>{this._status=l.RESOLVED,this._cleanUp()}),(()=>{this._status=l.REJECTED,this._cleanUp()})),this.promise=this._resolver.promise}destroy(){this._cleanUp()}addResolvingPromise(s){this._resolvingPromises.push(s),this._tryResolve()}isResolved(){return this._status===l.RESOLVED}isRejected(){return this._status===l.REJECTED}isFulfilled(){return this._status!==l.PENDING}abort(){this._resolver.reject(r())}_cleanUp(){this._allPromise=null,this._resolvingPromises=null}_tryResolve(){if(this.isFulfilled())return;const s=i(),e=[...this._resolvingPromises,s.promise],r=this._allPromise=Promise.all(e);r.then((()=>{this.isFulfilled()||this._allPromise!==r||this._resolver.resolve()}),(s=>{this.isFulfilled()||this._allPromise!==r||t(s)||this._resolver.reject(s)})),s.resolve()}}const n=e=>{let i=class extends e{constructor(...s){super(...s),this._promiseProps=new h,this.addResolvingPromise(Promise.resolve())}destroy(){this._promiseProps.destroy()}isResolved(){return this._promiseProps.isResolved()}isRejected(){return this._promiseProps.isRejected()}isFulfilled(){return this._promiseProps.isFulfilled()}when(s,e){return this._promiseProps.promise.then((()=>this)).then(s,e)}catch(s){return this.when(null,s)}addResolvingPromise(s){s&&!this._promiseProps.isFulfilled()&&this._promiseProps.addResolvingPromise("_promiseProps"in s?s.when():s)}};return i=s([o("esri.core.Promise")],i),i};let m=class extends(n(e)){};m=s([o("esri.core.Promise")],m),function(s){s.EsriPromiseMixin=n}(m||(m={}));export{m as default};