Create pLimit(concurrency) that returns a limiter function to run at most N promises concurrently, queuing the rest.
Skip to solutionKEEP THE
mediumFrontend
Implement p-limit — concurrency limiter for async tasks
61 views
01
Understand the problem
concurrencyp-limitpromises
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
Approach: Queue + active count. limit(fn) enqueues and tries to run. runNext dequeues if active < concurrency, increments active, awaits fn, then decrements and recurses.
function pLimit(concurrency) {
let active = 0;
const queue = [];
const next = () => {
if (active >= concurrency ||
Solution ready — 2 min read
Classified // press E to declassify
04
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 148 of 190 decoded in the JavaScript Coding track. One more won't hurt.