import{__module as n}from"../../_virtual/queue.mjs";import{__require as r}from"../reusify/reusify.mjs";var e;function u(){if(e)return n.exports;e=1;var u=r();function t(n,r,e){if("function"==typeof n&&(e=r,r=n,n=null),!(e>=1))throw new Error("fastqueue concurrency must be equal to or greater than 1");var t=u(a),o=null,i=null,c=0,f=null,s={push:function(u,a){var v=t.get();v.context=n,v.release=d,v.value=u,v.callback=a||l,v.errorHandler=f,c>=e||s.paused?i?(i.next=v,i=v):(o=v,i=v,s.saturated()):(c++,r.call(n,v.value,v.worked))},drain:l,saturated:l,pause:function(){s.paused=!0},paused:!1,get concurrency(){return e},set concurrency(n){if(!(n>=1))throw new Error("fastqueue concurrency must be equal to or greater than 1");if(e=n,!s.paused)for(;o&&c<e;)c++,d()},running:function(){return c},resume:function(){if(!s.paused)return;if(s.paused=!1,null===o)return c++,void d();for(;o&&c<e;)c++,d()},idle:function(){return 0===c&&0===s.length()},length:function(){var n=o,r=0;for(;n;)n=n.next,r++;return r},getQueue:function(){var n=o,r=[];for(;n;)r.push(n.value),n=n.next;return r},unshift:function(u,a){var v=t.get();v.context=n,v.release=d,v.value=u,v.callback=a||l,v.errorHandler=f,c>=e||s.paused?o?(v.next=o,o=v):(o=v,i=v,s.saturated()):(c++,r.call(n,v.value,v.worked))},empty:l,kill:function(){o=null,i=null,s.drain=l},killAndDrain:function(){o=null,i=null,s.drain(),s.drain=l},error:function(n){f=n},abort:function(){var n=o;o=null,i=null;for(;n;){var r=n.next,e=n.callback,u=n.errorHandler,t=n.value,a=n.context;n.value=null,n.callback=l,n.errorHandler=null,u&&u(new Error("abort"),t),e.call(a,new Error("abort")),n.release(n),n=r}s.drain=l}};return s;function d(u){u&&t.release(u);var l=o;l&&c<=e?s.paused?c--:(i===o&&(i=null),o=l.next,l.next=null,r.call(n,l.value,l.worked),null===i&&s.empty()):0===--c&&s.drain()}}function l(){}function a(){this.value=null,this.callback=l,this.next=null,this.release=l,this.context=null,this.errorHandler=null;var n=this;this.worked=function(r,e){var u=n.callback,t=n.errorHandler,a=n.value;n.value=null,n.callback=l,n.errorHandler&&t(r,a),u.call(n.context,r,e),n.release(n)}}return n.exports=t,n.exports.promise=function(n,r,e){"function"==typeof n&&(e=r,r=n,n=null);var u=t(n,function(n,e){r.call(this,n).then(function(n){e(null,n)},e)},e),a=u.push,o=u.unshift;return u.push=function(n){var r=new Promise(function(r,e){a(n,function(n,u){n?e(n):r(u)})});return r.catch(l),r},u.unshift=function(n){var r=new Promise(function(r,e){o(n,function(n,u){n?e(n):r(u)})});return r.catch(l),r},u.drained=function(){return new Promise(function(n){process.nextTick(function(){if(u.idle())n();else{var r=u.drain;u.drain=function(){"function"==typeof r&&r(),n(),u.drain=r}}})})},u},n.exports}export{u as __require};