Skip to content

loopAwaits

Reports using await expressions inside loops.

✅ This rule is included in the performance logical presets.

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.

AEasy5<3 sp ansty="le--0:#C792EA;--1:#8844">AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0processIte1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53ite7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri53<[]sp ansty="le--0:#D9F5DD;--1:#1111">1<1)sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEf53< (sp ansty="le--0:#C792EA;--1:#8844">AEconsB0itA7253 items)< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEawa5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0fet5<3(sp ansty="le--0:#D6DEEB;--1:#403F">5<3`sp ansty="le--0:#ECC48D;--1:#3B61">B0/ap34<${sp ansty="le--0:#D6DEEB;--1:#403F">53it3<4}sp ansty="le--0:#D6DEEB;--1:#403F">5<3`sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEasy5<3 sp ansty="le--0:#C792EA;--1:#8844">AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0updateRecor1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53i7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb53<[]sp ansty="le--0:#D9F5DD;--1:#1111">1<1)sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEle5<3isp ansty="le--0:#C792EA;--1:#8844">AE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEwhi53 (A53 iA72leng53)< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEawa53 databaAB0upda53(ids[i]<);d ivclassNa="meec-li">53 < sp ansty="le--0:#D6DEEB;--1:#403F">53AE<+=sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AEa344AEfunc361B0processI1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53i6361B0st3F<53[] spans="tyle--0:#D9F5DD;--1:#11">1<111) spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44AEco61B0prom44A3F53i4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0map spans="tyle--0:#D6DEEB;--1:#40">31<111( spans="tyle--0:#D7DBE0;--1:#40">3F531<111) spans="tyle--0:#C792EA;--1:#88">44AE< => spans="tyle--0:#82AAFF;--1:#3B">61B0f >3361B0/38<34${ spans="tyle--0:#D6DEEB;--1:#40">3F533<834} spans="tyle--0:#D6DEEB;--1:#40">33F5<3)) ;divclass="Nameec-">de44AEa361B0Pro4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0all spans="tyle--0:#D6DEEB;--1:#40">3F53(promis3<);><}di vdivclass="Nameexpressive-">44AEa344AEfunc361B0updateRec1<111( spans="tyle--0:#D7DBE0;--1:#40">3F5<3ids spans="tyle--0:#7FDBCA;--1:#09">6361B0nu3F<53[] spans="tyle--0:#D9F5DD;--1:#11">1<111) spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44AEa361B0Pro4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0all spans="tyle--0:#D6DEEB;--1:#40">3F53<(ids spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0map spans="tyle--0:#D6DEEB;--1:#40">31<111( spans="tyle--0:#D7DBE0;--1:#40">3F<53id spans="tyle--0:#D9F5DD;--1:#11">1<111) spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F53 data>4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0up3F53(id<))) ;divclass="Nameec-">3<);>

This rule is not configurable.

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.