Skip to content

Await In Loop (ARCH3030)

Key typescript.async.await-in-loop · Severity info · Category async

Awaiting inside a for/while loop body over an array serializes independent async operations that could run concurrently with Promise.all.

async function loadAll(ids: string[]): Promise<User[]> {
const users: User[] = [];
for (const id of ids) {
users.push(await fetchUser(id)); // serial, slow
}
return users;
}
async function loadAll(ids: string[]): Promise<User[]> {
return Promise.all(ids.map((id) => fetchUser(id)));
}

Run independent operations concurrently with Promise.all; await in a loop only when there is a genuine sequential dependency.