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">AEfuncti3 sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0processIte3 sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53ite1(sp>7<2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri3 sp>53<[]sp ansty="le--0:#D9F5DD;--1:#1111">1[]sp><1)sp ansty="le--0:#D6DEEB;--1:#403F">531)sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEf sp>53< (sp ansty="le--0:#C792EA;--1:#8844">AEcons (sp>B0itA7253 items) {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEawa sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0fet3 sp>5<3(sp ansty="le--0:#D6DEEB;--1:#403F">53(sp><3`sp ansty="le--0:#ECC48D;--1:#3B61">B0/ap3`sp>34<${sp ansty="le--0:#D6DEEB;--1:#403F">53it${sp>3<4}sp ansty="le--0:#D6DEEB;--1:#403F">54}sp><3`sp ansty="le--0:#D6DEEB;--1:#403F">533`sp> {d><);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>);d><3}d ivclassNa="meec-li">53}d><3}d ivclassNa="meco"><}d>}d>3}d>AEasy5<3 sp ansty="le--0:#C792EA;--1:#8844">AEfuncti3 sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0updateRecor3 sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53i1(sp>7<2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb3 sp>53<[]sp ansty="le--0:#D9F5DD;--1:#1111">1[]sp><1)sp ansty="le--0:#D6DEEB;--1:#403F">531)sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEle sp>5<3isp ansty="le--0:#C792EA;--1:#8844">AE 3isp><= sp ansty="le--0:#F78C6C;--1:#AA09">8= sp><20sp ansty="le--0:#D6DEEB;--1:#403F">520sp> {d><3;d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEwhi sp>53 (A53 iA72leng53)3;d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEawa sp>53 databaAB0upda53(ids[i] {d><);d ivclassNa="meec-li">53 < sp ansty="le--0:#D6DEEB;--1:#403F">53 sp>AE<+=sp ansty="le--0:#D6DEEB;--1:#403F">5+=sp><3 sp ansty="le--0:#F78C6C;--1:#AA09">83 sp><21sp ansty="le--0:#D6DEEB;--1:#403F">521sp>);d><3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>3;d><3}d ivclassNa="meec-li">53}d><3}d ivclassNa="meco"><}d>}d>3}d> 44AEa344AEfunc361B0processI1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53i111(>6361B0st3F<53[] spans="tyle--0:#D9F5DD;--1:#11">153[]><111) spans="tyle--0:#D6DEEB;--1:#40">3F111)><53 {divclass="Nameec-">de44AEco61B0prom44A3F53i4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B4AE.><0map spans="tyle--0:#D6DEEB;--1:#40">30map>1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53111(>- 1
<111) spans="tyle--0:#C792EA;--1:#88">44AE111)>< => spans="tyle--0:#82AAFF;--1:#3B">61B0f => >3361B0/38<34${ spans="tyle--0:#D6DEEB;--1:#40">3F5334${>- 3
<834} spans="tyle--0:#D6DEEB;--1:#40">3834}>3F553 ><3)) ;divclass="Nameec-">de44AEa361B0Pro4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B4AE.><0all spans="tyle--0:#D6DEEB;--1:#40">3F53(promis0all>3))>3 fetch(`/api/${item}`)); await Promise.all(promises"><);>);><}di vdivclass="Nameexpressive-">44AEa344AEfunc361B0updateRec1<111( spans="tyle--0:#D7DBE0;--1:#40">3F5111(><3ids spans="tyle--0:#7FDBCA;--1:#09">63ids>361B0nu3F<53[] spans="tyle--0:#D9F5DD;--1:#11">153[]><111) spans="tyle--0:#D6DEEB;--1:#40">3F111)><53 {divclass="Nameec-">de44AEa361B0Pro4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B4AE.><0all spans="tyle--0:#D6DEEB;--1:#40">3F530all><(ids spans="tyle--0:#C792EA;--1:#88">4(ids><4AE. spans="tyle--0:#82AAFF;--1:#3B">61B4AE.><0map spans="tyle--0:#D6DEEB;--1:#40">30map>1<111( spans="tyle--0:#D7DBE0;--1:#40">3F111(><53id spans="tyle--0:#D9F5DD;--1:#11">153id><111) spans="tyle--0:#D6DEEB;--1:#40">3111)>44 spans="tyle--0:#D6DEEB;--1:#40">3F53 data>4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0up4AE.>3F53(id53 ><))) ;divclass="Nameec-">3)))> database.update(id))"><);>);>}di>
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.