/* Socket Lib - Built with esbuild */
var g=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var I=(n,e)=>{for(var r in e)g(n,r,{get:e[r],enumerable:!0})},v=(n,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of S(e))!z.call(n,t)&&t!==r&&g(n,t,{get:()=>e[t],enumerable:!(o=F(e,t))||o.enumerable});return n};var A=n=>v(g({},"__esModule",{value:!0}),n);var K={};I(K,{normalizeIterationOptions:()=>w,normalizeRetryOptions:()=>y,pEach:()=>j,pEachChunk:()=>q,pFilter:()=>N,pFilterChunk:()=>C,pRetry:()=>h,resolveRetryOptions:()=>x});module.exports=A(K);var T=require("#constants/core"),M=require("#constants/process"),O=require("./arrays");const P=(0,M.getAbortSignal)();let k;function E(){return k===void 0&&(k=require("node:timers/promises")),k}function w(n){const e=typeof n=="number"?{concurrency:n}:n,{concurrency:r=1,retries:o,signal:t=P}={__proto__:null,...e};return{__proto__:null,concurrency:Math.max(1,r),retries:y({signal:t,...x(o)}),signal:t}}function y(n){const e=x(n),{args:r=[],backoffFactor:o=e.factor||2,baseDelayMs:t=e.minTimeout||200,jitter:u=!0,maxDelayMs:i=e.maxTimeout||1e4,onRetry:s,onRetryCancelOnFalse:c=!1,onRetryRethrow:f=!1,retries:m=e.retries||0,signal:a=P}=e;return{args:r,backoffFactor:o,baseDelayMs:t,jitter:u,maxDelayMs:i,minTimeout:t,maxTimeout:i,onRetry:s,onRetryCancelOnFalse:c,onRetryRethrow:f,retries:m,signal:a}}function x(n){const e={__proto__:null,retries:0,minTimeout:200,maxTimeout:1e4,factor:2};return typeof n=="number"?{...e,retries:n}:n?{...e,...n}:e}async function j(n,e,r){const o=w(r),{concurrency:t,retries:u,signal:i}=o,s=(0,O.arrayChunk)(n,t);for(const c of s){if(i?.aborted)return;await Promise.all(c.map(f=>h((...m)=>e(m[0]),{...u,args:[f],signal:i})))}}async function N(n,e,r){const o=w(r);return(await C((0,O.arrayChunk)(n,o.concurrency),e,o.retries)).flat()}async function q(n,e,r){const{chunkSize:o=100,...t}=r||{},u=(0,O.arrayChunk)(n,o),i=y(t),{signal:s}=i;for(const c of u){if(s?.aborted)return;await h((...f)=>e(f[0]),{...i,args:[c]})}}async function C(n,e,r){const o=y(r),{signal:t}=o,{length:u}=n,i=Array(u);for(let s=0;s<u;s+=1)if(t?.aborted)i[s]=[];else{const c=n[s],f=await Promise.all(c.map(m=>h((...a)=>e(a[0]),{...o,args:[m]})));i[s]=c.filter((m,a)=>f[a])}return i}async function h(n,e){const{args:r,backoffFactor:o,baseDelayMs:t,jitter:u,maxDelayMs:i,onRetry:s,onRetryCancelOnFalse:c,onRetryRethrow:f,retries:m,signal:a}=y(e);if(a?.aborted)return;if(m===0)return await n(...r||[],{signal:a});const D=E();let R=m,p=t,b=T.UNDEFINED_TOKEN;for(;R-->=0;){if(a?.aborted)return;try{return await n(...r||[],{signal:a})}catch(_){if(b===T.UNDEFINED_TOKEN&&(b=_),R<0)break;let d=p;if(u&&(d+=Math.floor(Math.random()*p)),d=Math.min(d,i),typeof s=="function")try{const l=s(m-R,_,d);if(l===!1&&c)break;typeof l=="number"&&l>=0&&(d=Math.min(l,i))}catch(l){if(f)throw l}try{await D.setTimeout(d,void 0,{signal:a})}catch{return}if(a?.aborted)return;p=Math.min(p*o,i)}}if(b!==T.UNDEFINED_TOKEN)throw b}0&&(module.exports={normalizeIterationOptions,normalizeRetryOptions,pEach,pEachChunk,pFilter,pFilterChunk,pRetry,resolveRetryOptions});
//# sourceMappingURL=promises.js.map
