Skip to main content

no-await-in-loop

Performing await operations sequentially in a loop prevents taking advantage of the parallelization benefits of async/await.
Rule Type: Problem
Fixable: No

Why This Rule Exists

Using await inside a loop means each iteration must complete before the next one starts. Usually, you can refactor this code to create all promises at once, then use Promise.all() to wait for them all to complete in parallel.

Sequential vs Parallel

Rule Details

This rule disallows the use of await within loop bodies.

Error Handling Benefits

Parallel execution also improves error handling by preventing unhandled promise rejections:

Examples

Incorrect Code

Correct Code

When Not to Use It

There are legitimate cases where sequential await is necessary:

Serial Operations

It’s safe to disable this rule when iterations actually depend on each other.

Rate Limiting

Resource Constraints

Dependent Iterations

Intentional Delays

File System Operations

Disabling for Specific Cases

When you have a legitimate use case, disable the rule with a comment: