Build a queue that enqueues async tasks and runs up to concurrency at once. Support pause/resume and onIdle.
Skip to solutionKEEP THE
mediumFrontend
Implement a Promise Queue (TaskQueue) with concurrency
932 views
01
Understand the problem
promisequeueconcurrency
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: Similar to p-limit but as a class with add, pause, onIdle.
class TaskQueue {
constructor(concurrency = 2) { this.concurrency = concurrency; this.running = 0; this.queue = []; this.paused = false; }
add(task) {
return new Promise((resolve, reject) => {
this.queue.push({ t
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 120 of 190 decoded in the JavaScript Coding track. One more won't hurt.