no-await-in-loop
Performingawait operations sequentially in a loop prevents taking advantage of the parallelization benefits of async/await.
Rule Type: Problem
Fixable: No
Fixable: No
Why This Rule Exists
Usingawait 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 ofawait 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 sequentialawait is necessary: