async function f(e,n,i){const o=[],t=[];for(const c of e){const s=Promise.resolve().then(()=>i(c,e));if(o.push(s),n<=e.length){const r=s.then(()=>t.splice(t.indexOf(r),1));t.push(r),t.length>=n&&await Promise.race(t)}}return Promise.all(o)}async function l(e,n,i,o){const t=await f(e,n,async r=>{try{return await i(r),{status:"ok"}}catch(a){const u=a instanceof Error?a:new Error(String(a));return o?.error("Processing failed for item:",u),{status:"error",error:u}}}),c=t.filter(r=>r.status==="ok").length,s=t.filter(r=>r.status==="error").length;return{result:t,count:{ok:c,failed:s}}}export{f as promiseMapLimit,l as promiseMapLimitWithStatus};
