(function(t,r){typeof exports=="object"&&typeof module<"u"?module.exports=r():typeof define=="function"&&define.amd?define(r):(t=typeof globalThis<"u"?globalThis:t||self,t.pWorker=r())})(this,function(){"use strict";function t(r){if(r.length===0)throw new Error("cannot create a worker with a concurrency of zero!");const i=r.map((n,o)=>{const e={shared:n,index:o,counter:0};return e.promise=Promise.resolve(e),e});return async function(n){let o,e;do o=i.map(u=>u.counter),e=await Promise.race(i.map(u=>u.promise));while(e.counter!==o[e.index]);e.counter+=1,e.counter===Number.MAX_SAFE_INTEGER&&(e.counter=0);const s=n(e.shared);return e.promise=s.then(()=>e,()=>e),await s}}return t});