---
title: "Await inside a loop (data/await-in-loop)"
description: "Each iteration waits for the previous round trip before starting its own: N items cost N sequential database or network latencies on the request path."
url: http://localhost:4173/rules/data/await-in-loop
updated: 2026-11-11
---

# Await inside a loop

> `data/await-in-loop` is a vetd rule. It flags: Await inside a loop. It runs on every `check`, together with the TypeScript check.

| Fact | Value |
| --- | --- |
| Rule id | `data/await-in-loop` |
| Severity | warning |
| Group | Data fetching |
| Tags | performance, correctness |

## Why it matters

Each iteration waits for the previous round trip before starting its own: N items cost N sequential database or network latencies on the request path.

## How to fix it

Start the calls together and await them once (`await Promise.all(items.map(load))`), or fetch them all in one batched query (`where: { id: { in: ids } }`).

## Credit

Based on work by:

- [ESLint](https://eslint.org): The no-await-in-loop rule flags awaiting inside a loop because iterations then run one after another.

## References

- [no-await-in-loop](https://eslint.org/docs/latest/rules/no-await-in-loop), ESLint
- [Promise.all() - JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all), MDN Web Docs
- [Fetching Data](https://nextjs.org/docs/app/getting-started/fetching-data), Next.js

## See it

Demos in the vetd Lab:

- [Start early, await late](http://localhost:4173/lab/react-perf/eliminate-async-waterfalls)
- [Fetch in parallel](http://localhost:4173/lab/nextjs/parallel-fetching)

## Related rules

- [`next/sequential-await`](http://localhost:4173/rules/next/sequential-await.md)
- [`data/serial-route-fetch`](http://localhost:4173/rules/data/serial-route-fetch.md)

## Get this text from vetd

MCP: call `explain` with `{ "diagnosticId": "data/await-in-loop" }`. CLI: `npx vetd explain data/await-in-loop`.

---

[All 92 rules](http://localhost:4173/rules.md) · Previous: [`perf/dynamic-ssr-false`](http://localhost:4173/rules/perf/dynamic-ssr-false.md) · Next: [`data/self-fetch`](http://localhost:4173/rules/data/self-fetch.md)
