/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","./events","./handleUtils","./maybe","./promiseUtils","./accessorSupport/watch","./accessorSupport/trackingUtils"],(function(n,e,t,r,o,u,i){"use strict";function c(n,e,t={}){return s(n,e,t,v)}function l(n,e,t={}){return s(n,e,t,y)}function s(n,e,t={},o){let i=null;const c=t.once?(n,t)=>{o(n)&&(r.removeMaybe(i),e(n,t))}:(n,t)=>{o(n)&&e(n,t)};if(i=u.watchTracked(n,c,t.sync,t.equals),t.initial){const e=n();c(e,e)}return i}function a(n,o,u,i={}){let l=null,s=null,a=null;function f(){l&&s&&(s.remove(),null==i.onListenerRemove||i.onListenerRemove(l),l=null,s=null)}function m(n){i.once&&i.once&&r.removeMaybe(a),u(n)}const d=c(n,((n,t)=>{f(),e.isEventTarget(n)&&(l=n,s=e.on(n,o,m),null==i.onListenerAdd||i.onListenerAdd(n))}),{sync:i.sync,initial:!0});return a=t.makeHandle((()=>{d.remove(),f()})),a}function f(n,e){return d(n,null,e)}function m(n,e){return d(n,y,e)}function d(n,e,u){if(o.isAborted(u))return Promise.reject(o.createAbortError());const i=n();if(null!=e&&e(i))return Promise.resolve(i);let c=null;function l(){c=r.removeMaybe(c)}return new Promise(((r,i)=>{c=t.handlesGroup([o.onAbort(u,(()=>{l(),i(o.createAbortError())})),s(n,(n=>{l(),r(n)}),{sync:!1,once:!0},null!=e?e:v)])}))}function v(n){return!0}function y(n){return!!n}function b(n,e,t={}){let r=!1;const o=c(n,((n,t)=>{r||e(n,t)}),t);return{remove(){o.remove()},pause(){r=!0},resume(){r=!1}}}const p={sync:!0},h={initial:!0},A={sync:!0,initial:!0};n.autorun=i.autorun,n.initial=h,n.on=a,n.once=f,n.pausable=b,n.sync=p,n.syncAndInitial=A,n.watch=c,n.when=l,n.whenOnce=m,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
