Skip to main content

No Await In Loop

Disallow await inside loops so sequential calls that should be parallelized with Promise.all() are caught early.

Summary

The no-await-in-loop rule reports any await expression found inside a loop. By default, all loop types are disallowed.

Use the configuration options to allow specific loop types (e.g., for...of for order-dependent iteration, while for pagination).

Why Use This Rule?

  1. Catches sequential network calls that should be parallelized for performance.
  2. Provides fine-grained control over which loop types are allowed to contain await.
  3. Keeps configuration centralized in the ESLint config rather than scattered across inline comments.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
allowForbooleanfalseAllow await inside C-style for loops.
allowForInbooleanfalseAllow await inside for...in loops.
allowForOfbooleanfalseAllow await inside for...of loops.
allowWhilebooleanfalseAllow await inside while and do...while loops.
ignoreFilesstring[][]File patterns to skip.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Await in for...of is flagged — By default, allowForOf is false. Set it to true if you want to allow await in for...of loops.
  • Warning fires outside a loop — The rule only checks await inside loop bodies. If the warning appears elsewhere, the await may be inside a nested loop you did not notice.