// @bun
import{OG as w}from"./chunk-xyhgvt88.js";async function M(z,Z,{concurrency:q=Number.POSITIVE_INFINITY,stopOnError:A=!0,signal:J}={}){return new Promise((B,Q)=>{if(z[Symbol.iterator]===void 0&&z[Symbol.asyncIterator]===void 0)throw TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof z})`);if(typeof Z!=="function")throw TypeError("Mapper function is required");if(!(Number.isSafeInteger(q)&&q>=1||q===Number.POSITIVE_INFINITY))throw TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${q}\` (${typeof q})`);let X=[],$=[],K=new Map,N=!1,F=!1,T=!1,G=0,f=0,_=z[Symbol.iterator]===void 0?z[Symbol.asyncIterator]():z[Symbol.iterator](),D=()=>{Y(J.reason)},E=()=>{J?.removeEventListener("abort",D)},O=(H)=>{B(H),E()},Y=(H)=>{N=!0,F=!0,Q(H),E()};if(J){if(J.aborted)Y(J.reason);J.addEventListener("abort",D,{once:!0})}let V=async()=>{if(F)return;let H=await _.next(),h=f;if(f++,H.done){if(T=!0,G===0&&!F){if(!A&&$.length>0){Y(AggregateError($));return}if(F=!0,K.size===0){O(X);return}let U=[];for(let[W,P]of X.entries()){if(K.get(W)===L)continue;U.push(P)}O(U)}return}G++,(async()=>{try{let U=await H.value;if(F)return;let W=await Z(U,h);if(W===L)K.set(h,W);X[h]=W,G--,await V()}catch(U){if(A)Y(U);else{$.push(U),G--;try{await V()}catch(W){Y(W)}}}})()};(async()=>{for(let H=0;H<q;H++){try{await V()}catch(h){Y(h);break}if(T||N)break}})()})}function I(z,Z,{concurrency:q=Number.POSITIVE_INFINITY,backpressure:A=q}={}){if(z[Symbol.iterator]===void 0&&z[Symbol.asyncIterator]===void 0)throw TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof z})`);if(typeof Z!=="function")throw TypeError("Mapper function is required");if(!(Number.isSafeInteger(q)&&q>=1||q===Number.POSITIVE_INFINITY))throw TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${q}\` (${typeof q})`);if(!(Number.isSafeInteger(A)&&A>=q||A===Number.POSITIVE_INFINITY))throw TypeError(`Expected \`backpressure\` to be an integer from \`concurrency\` (${q}) and up or \`Infinity\`, got \`${A}\` (${typeof A})`);return{async*[Symbol.asyncIterator](){let J=z[Symbol.asyncIterator]===void 0?z[Symbol.iterator]():z[Symbol.asyncIterator](),B=[],Q=0,X=!1,$=0;function K(){if(X||!(Q<q&&B.length<A))return;Q++;let N=(async()=>{let{done:F,value:T}=await J.next();if(F)return Q--,{done:!0};K();try{let G=await Z(await T,$++);if(Q--,G===L){let f=B.indexOf(N);if(f>0)B.splice(f,1)}return K(),{done:!1,value:G}}catch(G){return Q--,X=!0,{error:G}}})();B.push(N)}K();while(B.length>0){let{error:N,done:F,value:T}=await B[0];if(B.shift(),N)throw N;if(F)return;if(K(),T===L)continue;yield T}}}}var L;var C=w(()=>{L=Symbol("skip")});C();export{L as pMapSkip,I as pMapIterable,M as default};
