E3 — Promise Pool/Queue (async concurrency)
Run many async tasks with a small concurrency limit. Keep a queue, start a few at a time, and collect results.
What and why
Goal: Run many async jobs without flooding the system.
- Limit concurrency (e.g., 2 at a time)
- Keep a simple queue index
- Store results in an array
- Beginner-friendly code, small helpers

Async job helper
A tiny helper returns a Promise that resolves after a delay; optionally fails for testing.
// Simulate async work with setTimeout
function fakeJob(name, ms, fail) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
if (fail) {
reject(new Error("fail:" + name));
} else {
resolve("done:" + name);
}
}, ms);
});
}
console.log("demo job:", typeof fakeJob === "function");
All lessons in this course
- E1 — Expression Evaluator (part 1: + and - LTR)
- E2 — Log Analyzer (simple filters & counters)
- E3 — Promise Pool/Queue (async concurrency)