var h=Object.defineProperty;var o=(e,r,t)=>r in e?h(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var i=(e,r,t)=>o(e,typeof r!="symbol"?r+"":r,t);var s=class{constructor(e){i(this,"waiters",[]);if(!Number.isInteger(e)||e<1)throw Error(`Semaphore permits must be a positive integer, got ${e}`);this.maxPermits=e,this.permits=e}get available(){return this.permits}get pending(){return this.waiters.length}acquire(){return this.permits>0?(this.permits--,Promise.resolve()):new Promise(e=>{this.waiters.push(e)})}release(){let e=this.waiters.shift();if(e){e();return}if(this.permits>=this.maxPermits)throw Error("Semaphore.release() called more times than acquire() \u2014 refusing to exceed initial permit count");this.permits++}async run(e){await this.acquire();try{return await e()}finally{this.release()}}};function l(e,r,t){let a=new s(r);return e.length===0?Promise.resolve([]):Promise.all(e.map((n,m)=>a.run(()=>t(n,m))))}export{l as n,s as t};
