/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{createTask as t,resultOrAbort as e}from"../../../../../core/asyncUtils.js";class s{constructor(t,e){this.key=t,this.resolution=e,this.state={type:0},this.alive=!0}process(t){switch(this.state.type){case 0:return this.state=this._gotoFetchCount(this.state,t),this.state.task.promise.then(t.resume,t.resume);case 1:case 3:break;case 2:return this.state=this._gotoFetchFeatures(this.state,t),this.state.task.promise.then(t.resume,t.resume);case 4:this.state=this._goToDone(this.state,t)}return null}get debugInfo(){return{key:this.key,featureCount:this._featureCount,state:this._stateToString}}get _featureCount(){switch(this.state.type){case 0:case 1:return 0;case 2:return this.state.featureCount;case 3:return this.state.previous.featureCount;case 4:return this.state.features.length;case 5:return this.state.previous.features.length}}get _stateToString(){switch(this.state.type){case 0:return"created";case 1:return"fetch-count";case 2:return"fetched-count";case 3:return"fetch-features";case 4:return"fetched-features";case 5:return"done"}}_gotoFetchCount(s,r){return{type:1,previous:s,task:t(async t=>{const s=await e(r.fetchCount(this,t));1===this.state.type&&(this.state=a(this.state,s.ok?s.value:1/0))})}}_gotoFetchFeatures(s,a){return{type:3,previous:s,task:t(async t=>{const u=await e(a.fetchFeatures(this,s.featureCount,t));3===this.state.type&&(this.state=r(this.state,u.ok?u.value:[]))})}}_goToDone(t,e){return e.finish(this,t.features),{type:5,previous:t}}reset(){const t=this.state;switch(this.state={type:0},t.type){case 0:case 2:case 4:case 5:break;case 1:case 3:t.task.abort()}}}function a(t,e){return{type:2,featureCount:e,previous:t}}function r(t,e){return{type:4,previous:t,features:e}}export{s as PendingFeatureTile};
