/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../chunks/_rollupPluginBabelHelpers","./clock","./deprecate","./Error","./events","./Logger","./maybe"],(function(e,r,t,n,o,i,s,u){"use strict";function c(e,r){return l.apply(this,arguments)}function l(){return(l=r._asyncToGenerator((function*(e,r){const t=e.slice(),n=yield Promise.all(e.map(((e,t)=>r(e,t))));return t.filter(((e,r)=>n[r]))}))).apply(this,arguments)}function a(e){return n.deprecatedFunction(s.getLogger("esri.core.promiseUtils"),"create",{moduleName:"esri.core.promiseUtils",replacement:"new Promise()",version:"4.24"}),new Promise(((r,t)=>{try{e(r,t)}catch(n){Promise.resolve().then((()=>t(n)))}}))}function f(e="Aborted"){return new o("AbortError",e)}function m(e,r="Aborted"){if(p(e))throw f(r)}function h(e){return u.isSome(e)?"aborted"in e?e:e.signal:e}function p(e){const r=h(e);return u.isSome(r)&&r.aborted}function b(e){if(T(e))throw e}function y(e){if(!T(e))throw e}function w(e,r){const t=h(e);if(!u.isNone(t)){if(!t.aborted)return i.once(t,"abort",(()=>r()));r()}}function d(e,r){const t=h(e);if(!u.isNone(t))return m(t),i.once(t,"abort",(()=>r(f())))}function v(e,r){const t=h(r);return u.isNone(t)?e:new Promise(((t,n)=>{let o=w(r,(()=>n(f())));const i=()=>o=u.removeMaybe(o);e.then(i,i),e.then(t,n)}))}function A(e,r,t){return Promise.race([e,S(r).then((()=>{throw new o("timeout",`Did not resolve within ${r} milliseconds (${null!=t?t:"timeout"})`)}))])}function T(e){return e&&"AbortError"===e.name}function g(e){return P.apply(this,arguments)}function P(){return(P=r._asyncToGenerator((function*(e){try{return yield e}catch(r){if(!T(r))throw r}}))).apply(this,arguments)}function E(e){return N.apply(this,arguments)}function N(){return(N=r._asyncToGenerator((function*(e,r=s.getLogger("esri")){try{return yield e}catch(t){T(t)||r.error(t)}}))).apply(this,arguments)}function _(){let e=null;const r=new Promise(((r,t)=>{e={promise:void 0,resolve:r,reject:t}}));return e.promise=r,e}function j(e){return k.apply(this,arguments)}function k(){return(k=r._asyncToGenerator((function*(e){if(!e)return;if("function"!=typeof e.forEach){const r=Object.keys(e),t=r.map((r=>e[r])),n=yield j(t),o={};return r.map(((e,r)=>o[e]=n[r])),o}const r=e;return new Promise((e=>{const t=[];let n=r.length;0===n&&e(t),r.forEach((r=>{const o={promise:r||Promise.resolve(r)};t.push(o),o.promise.then((e=>{o.value=e})).catch((e=>{o.error=e})).then((()=>{--n,0===n&&e(t)}))}))}))}))).apply(this,arguments)}function G(e){return O.apply(this,arguments)}function O(){return(O=r._asyncToGenerator((function*(e){return(yield j(e)).filter((e=>!!e.value)).map((e=>e.value))}))).apply(this,arguments)}function S(e,r,t){const n=new AbortController;return w(t,(()=>n.abort())),new Promise(((t,o)=>{let i=setTimeout((()=>{i=0,t(r)}),e);w(n,(()=>{i&&(clearTimeout(i),o(f()))}))}))}function L(e,r,t,n){const i=t&&"abort"in t?t:null;null!=n||i||(n=t);let s=setTimeout((()=>{s=0,i&&i.abort()}),r);const u=()=>n||new o("promiseUtils:timeout","The wrapped promise did not resolve within "+r+" ms");return e.then((e=>{if(0===s)throw u();return clearTimeout(s),e}),(e=>{throw clearTimeout(s),0===s?u():e}))}function C(e){return e&&"function"==typeof e.then}function I(e){return C(e)?e:Promise.resolve(e)}function M(e,r=-1){let t,n,o,i,s=null;const c=(...l)=>{if(t){n=l,i&&i.reject(f()),i=_();const e=u.assumeNonNull(i.promise);if(s){const e=s;s=null,e.abort()}return e}if(o=i||_(),i=null,r>0){const n=new AbortController;t=I(e(...l,n.signal));const o=t;S(r).then((()=>{t===o&&(i?n.abort():s=n)}))}else t=1,t=I(e(...l));const a=()=>{const e=n;n=o=t=s=null,null!=e&&c(...e)},m=t,h=o;return m.then(a,a),m.then(h.resolve,h.reject),u.assumeNonNull(h.promise)};return c}function U(){let e,r;const n=new Promise(((t,n)=>{e=t,r=n})),o=r=>{e(r)};return o.resolve=r=>e(r),o.reject=e=>r(e),o.timeout=(e,r)=>t.clock.setTimeout((()=>o.reject(r)),e),o.promise=n,o}function D(e,r){return e.then(r,r)}function $(e,r){let t,n=new AbortController;const o=e(n.signal);let i={promise:o,finished:!1,abort:()=>{n&&(n.abort(),n=null)}};const s=()=>{i&&(i.finished=!0,i=null),u.isSome(t)&&(t.remove(),t=null),n=null};return o.then(s,s),t=w(r,(()=>{u.isSome(i)&&i.abort()})),i}function x(e){return B.apply(this,arguments)}function B(){return(B=r._asyncToGenerator((function*(e){yield Promise.resolve(),m(e)}))).apply(this,arguments)}e.after=S,e.always=D,e.create=a,e.createAbortError=f,e.createDeferred=_,e.createResolver=U,e.createTask=$,e.debounce=M,e.eachAlways=j,e.eachAlwaysValues=G,e.filter=c,e.ignoreAbortErrors=g,e.isAbortError=T,e.isAborted=p,e.isPromiseLike=C,e.logOnError=E,e.onAbort=w,e.onAbortOrThrow=d,e.throwIfAbortError=b,e.throwIfAborted=m,e.throwIfNotAbortError=y,e.timeout=L,e.waitTick=x,e.when=I,e.whenOrAbort=v,e.whenOrTimeout=A,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
