Promise Pool Concurrent Map Backpressure
Run async tasks through a fixed concurrency pool with backpressure collecting results in order while limiting outstanding promises.
Code
export async function promisePool(items,worker,concurrency=4){const results=new Array(items.length);let next=0;async function run(){while(true){const i=next++;if(i>=items.length)return;results[i]=await worker(items[i],i);}}const runners=Array.from({length:Math.min(concurrency,items.length)},()=>run());await Promise.all(runners);return results;}Report a problem with this exampleOpens a pre-filled issue on GitHub.