Language concepts
Backpressure
Feedback mechanism by which a producer waits or slows when the consumer cannot accept more data. A concurrency limit does not by itself cap the total pending queue.
Formal Syntax & Structure
javascript syntaxjavascript
await consumerReady; produceNext();Working Example
Example Snippetjavascript
async function mapLimit(items, limit, fn) { if (!Number.isInteger(limit) || limit < 1) throw new RangeError("limit"); let next = 0; const out = []; async function worker() { while (next < items.length) { const i = next++; out[i] = await fn(items[i]); } } await Promise.all(Array.from({length:Math.min(limit,items.length)},worker)); return out;}let active=0, peak=0;mapLimit([1,2,3,4],2,async n=>{active++; peak=Math.max(peak,active); await 0; active--; return n*2;}).then(r=>console.log(r.join(","),peak));