- Notifications
You must be signed in to change notification settings - Fork0
plutoniumm/promisq
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Promise queue with concurrency control.
pnpm i promq
All options are optional
Option | Default | Description |
---|---|---|
concurrency | 6 | Number of concurrent jobs |
retry | 3 | Number of retries |
retryMethod | Jittered exponential backoff (in s) | Retry timing function |
retry_postpone | false | Postpone retry until all jobs are done |
// returns async function/ promisefunctionFactory(index){returnasync()=>{constwait=Math.random()*1000|0;awaitnewPromise((resolve)=>setTimeout(resolve,wait));}}importPQfrom'promq';constpq=newPQ({concurrency:2,retry:3,retryMethod:(count)=>(count**2*1000)*(Math.random()+1),retry_postpone:false,});// generally any async function can be addedfor(leti=0;i<5;i++){pq.add(Factory(i));}// runs 2 at a time
About
promise queue and fetch queue