Running hundreds of promises simultaneously can overload RPC nodes or exhaustion limits. A concurrency pool bounds active tasks.
js
async function asyncPool(limit, tasks) {
const executing = new Set();
for (const task of tasks) {
const p = Promise.resolve().then(task);
executing.add(p);
p.finally(() => executing.delete(p));
if (executing.size >= limit) await Promise.race(executing);
}
}