loopAwaits
Reports using await expressions inside loops.
✅ This rule is included in the performance preset.
Using await inside a loop causes each iteration to wait for the previous iteration to complete before starting the next one.
This sequential execution can significantly slow down your code when the awaited operations are independent and could be executed in parallel.
Consider collecting promises in an array during the loop and then using Promise.all() to await all of them in parallel.
This allows all the asynchronous operations to run concurrently, which is typically much faster than running them one at a time.
Examples
Section titled “Examples”async function processItems(items: string[]) { for (const item of items) { await fetch(`/api/${item}`); }}async function updateRecords(ids: number[]) { let i = 0; while (i < ids.length) { await database.update(ids[i]); i += 1; }}async function processItems(items: string[]) { const promises = items.map((item) => fetch(`/api/${item}`)); await Promise.all(promises);}async function updateRecords(ids: number[]) { await Promise.all(ids.map((id) => database.update(id)));}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your asynchronous operations must be executed sequentially you may wish to disable this rule for those specific cases. For example, if each operation depends on the result of the previous one, or if you need to avoid overwhelming a rate-limited API, parallel calls may not be an option.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noAwaitInLoops - Deno:
no-await-in-loop - ESLint:
no-await-in-loop - Oxlint:
eslint/no-await-in-loop