const p={trailing:!0};function y(a,i=25,e={}){if(e={...p,...e},!Number.isFinite(i))throw new TypeError("Expected `wait` to be a finite number");let o,r,s=[],t,l;const c=(n,u)=>(t=g(a,n,u),t.finally(()=>{if(t=null,e.trailing&&l&&!r){const f=c(n,l);return l=null,f}}),t);return function(...n){return t?(e.trailing&&(l=n),t):new Promise(u=>{const f=!r&&e.leading;clearTimeout(r),r=setTimeout(()=>{r=null;const m=e.leading?o:c(this,n);for(const d of s)d(m);s=[]},i),f?(o=c(this,n),u(o)):s.push(u)})}}async function g(a,i,e){return await a.apply(i,e)}export{y as d};
