"use strict";var ConcurrentCallbackQueue=(()=>{var z=Object.defineProperty;var v=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var L=r=>{throw TypeError(r)};var q=(r,t,e)=>t in r?z(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,g=(r,t)=>{for(var e in t||(t={}))M.call(t,e)&&q(r,e,t[e]);if(v)for(var e of v(t))N.call(t,e)&&q(r,e,t[e]);return r};var R=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var I=(r,t,e)=>t.has(r)||L("Cannot "+e);var s=(r,t,e)=>(I(r,t,"read from private field"),e?e.call(r):t.get(r)),b=(r,t,e)=>t.has(r)?L("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),S=(r,t,e,i)=>(I(r,t,"write to private field"),i?i.call(r,e):t.set(r,e),e),c=(r,t,e)=>(I(r,t,"access private method"),e);var O=(r,t,e,i)=>({set _(a){S(r,t,a,e)},get _(){return s(r,t,i)}});var U=(r,t,e)=>new Promise((i,a)=>{var w=p=>{try{D(e.next(p))}catch(P){a(P)}},k=p=>{try{D(e.throw(p))}catch(P){a(P)}},D=p=>p.done?i(p.value):Promise.resolve(p.value).then(w,k);D((e=e.apply(r,t)).next())});var F=R((H,j)=>{var E=()=>{},d=Object.freeze({autoStart:!0,maxConcurrent:10,onCallbackError:E,onCallbackSuccess:E,onQueueIdle:E,onQueueBusy:E,onQueueStop:E}),h=Object.freeze({IDLE:"IDLE",BUSY:"BUSY",STOPPED:"STOPPED"}),u,y,l,f,o,n,Y,m,C,x,Q,A,T=class T{constructor(t=d){b(this,n);b(this,u);b(this,y);b(this,l);b(this,f);b(this,o);S(this,u,[]),S(this,y,new Map),S(this,f,0),c(this,n,Y).call(this,t),S(this,l,s(this,o).autoStart?h.IDLE:h.STOPPED)}static create(t=d){return new T(t)}getState(){return s(this,l)}getPendingCount(){return s(this,u).length}getRunningCount(){return s(this,f)}getOptions(){return s(this,o)}enqueue(t,e=0){if(typeof t!="function")throw new Error('The "callback" parameter must be a function or a promise');if(typeof e!="number"||e<0)throw new Error('The "retries" parameter must be a positive number');s(this,u).push({callback:t,retries:e}),s(this,o).autoStart&&this.start()}enqueueAll(t,e=0){if(!Array.isArray(t)||!t.every(a=>typeof a=="function"))throw new Error('The "callbacks" parameter must be an array of functions or promises');if(typeof e!="number"||e<0)throw new Error('The "retries" parameter must be a positive number');let i=t.map(a=>({callback:a,retries:e}));s(this,u).push(...i),s(this,o).autoStart&&this.start()}dequeue(){return s(this,u).shift()}dequeueAll(){let t=s(this,u);return S(this,u,[]),t}start(){s(this,l)===h.BUSY||s(this,u).length===0||(c(this,n,m).call(this,h.BUSY),c(this,n,A).call(this))}stop(){c(this,n,m).call(this,h.STOPPED)}clear(){return this.stop(),this.dequeueAll()}};u=new WeakMap,y=new WeakMap,l=new WeakMap,f=new WeakMap,o=new WeakMap,n=new WeakSet,Y=function(t){S(this,o,g(g({},d),t||{}));let e=["onCallbackError","onCallbackSuccess","onQueueIdle","onQueueBusy","onQueueStop"];for(let i in s(this,o)){if(!(i in d)){delete s(this,o)[i];continue}e.includes(i)&&(!s(this,o)[i]||typeof s(this,o)[i]!="function")&&(s(this,o)[i]=E)}},m=function(t){let e=s(this,l);switch(S(this,l,t),t){case h.IDLE:s(this,o).onQueueIdle();break;case h.BUSY:s(this,o).onQueueBusy();break;case h.STOPPED:s(this,o).onQueueStop();break}return e},C=function(t){s(this,o).onCallbackError(t)},x=function(t){let e=t==null?void 0:t.callback,i=(t==null?void 0:t.retries)||0,a=w=>U(this,null,function*(){try{yield e()}catch(k){if(w<i)c(this,n,C).call(this,k),yield a(w+1);else throw k}});return()=>a(0)},Q=function(){if(s(this,l)===h.STOPPED||s(this,f)>=s(this,o).maxConcurrent)return;if(s(this,u).length===0){s(this,f)===0&&c(this,n,m).call(this,h.IDLE);return}let t=this.dequeue();if(!t){c(this,n,m).call(this,h.IDLE);return}let e=c(this,n,x).call(this,t),i=Date.now();Promise.resolve().then(()=>(O(this,f)._++,s(this,y).set(i,e),e())).then(()=>s(this,o).onCallbackSuccess()).catch(a=>c(this,n,C).call(this,a)).finally(()=>{O(this,f)._--,s(this,y).delete(i),s(this,l)===h.BUSY&&s(this,f)===0&&s(this,u).length===0&&c(this,n,m).call(this,h.IDLE)})},A=function(){c(this,n,Q).call(this);let t=setInterval(()=>{c(this,n,Q).call(this),(s(this,l)!==h.BUSY||s(this,u).length===0)&&clearInterval(t)})};var B=T;j.exports={ConcurrentCallbackQueue:B,QueueState:h,defaultQueueOptions:d}});return F();})();
/*! For license information please see ConcurrentCallbackQueue.iife.min.js.LEGAL.txt */
//# sourceMappingURL=ConcurrentCallbackQueue.iife.min.js.map
