/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{abortMaybe as t}from"../../../../core/maybe.js";import{isAbortError as o}from"../../../../core/promiseUtils.js";class r{constructor(t){this.schedule=t,this._abortController=null,this._loadStatus=0,this._loadError=null,this._loader=null,this.logger=null}destroy(){this.abortLoad()}get loadStatus(){return this._loadStatus}load(t,r){return 1===this._loadStatus?(t&&t(),this._loader??Promise.resolve()):2===this._loadStatus?(r&&r(this._loadError),this._loader??Promise.resolve()):(null==this._loader&&(this._abortController=new AbortController,this._loader=this.doLoad(this._abortController.signal).then(()=>{this._abortController=null,this._loadStatus=1},t=>{throw this._loadError=t,this._abortController=null,this._loadStatus=2,!o(t)&&this.logger&&t.message&&this.logger.warn(t.message),t})),this._loader.then(t,r).catch(()=>{}),this._loader)}abortLoad(){null!=this._abortController?this._abortController=t(this._abortController):0===this._loadStatus&&(this._loadStatus=2),this._loader=null}}export{r as Loadable};
