no-await-in-loop rule occurs when an await is inside a do while loop
See original GitHub issueHi I am new in using ESLint. I’ve noticed that ESLint does have a rule no-await-in-loop
. I’m kind of struggling to implement my logic due to the restriction of await
inside a loop
. the code below will get Promise {<pending>}
when i’m not appending the await
. but works perfectly fine if it has await
in it.
async searchElement(locator) {
let lookForElement;
let limitCounter;
do {
lookForElement = await this.client.isVisible(locator); //this line will have the no-await-in-loop
limitCounter = await this.client.isVisible(locator); //this line will have the no-await-in-loop
if (lookForElement === false) {
await this.swipe(81, 700, 81, 682); //this line will have the no-await-in-loop
await this.pauseForInSeconds(0.7); //this line will have the no-await-in-loop
} else {
await this.clickOn(locator); //this line will have the no-await-in-loop
break;
}
} while (limitCounter === false);
I believe that this code is valid but ESLint detecting all await should not be inside a loop. I would like to understand better on why there is such rule (I am very sorry I am very new to javascript and eslint). And since there is this rule. what are my other options to implement this logic since I really need to put it on a do while loop. Please let me know if you need more information. thanks alot.
P.S.
the temporary solution i’m doing now is to disable the rule by:
// eslint-disable-next-line no-await-in-loop
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@vamshi9 This really isn’t the place to discuss it, but the number of tasks you have isn’t changed by using a loop or by using iterative means. Ping me on irc or in gitter with your code and I’ll be happy to show you how to achieve it without loops.
This rule is assuming Promise.all() is always an option, which it usually isn’t. I was surprised by this rule. Nobody’s going to write a for loop with a bunch of async calls unless they need to run sequentially… right?