Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow await inside of loops (no-await-in-loop) #737

Closed
feross opened this issue Jan 7, 2017 · 5 comments

Comments

@feross
Copy link
Member

commented Jan 7, 2017

Performing an operation on each element of an iterable is a common task. However, performing an await as part of each operation is an indication that the program is not taking full advantage of the parallelization benefits of async/await.

Usually, the code should be refactored to create all the promises at once, then get access to the results using Promise.all(). Otherwise, each successive operation will not start until the previous one has completed.

http://eslint.org/docs/rules/no-await-in-loop

@feross feross added the enhancement label Jan 7, 2017

@feross feross added this to the standard v9 milestone Jan 7, 2017

@feross

This comment has been minimized.

Copy link
Member Author

commented Jan 7, 2017

No ecosystem impact.

@dougwilson

This comment has been minimized.

Copy link

commented Jan 10, 2017

There may be no current ecosystem impact (maybe from lack of widespread async function usage?), but I'm a little iffy on this rule. Maybe I just don't understand what I'm missing :) So my thought is that sometimes you want to go through an async loop in series, not parallel. This rule would seem to make that difficult, unless I'm missing something.

@feross

This comment has been minimized.

Copy link
Member Author

commented Jan 11, 2017

@dougwilson You're precisely right. This rule does make going through an async loop in series an error.

I was iffy as well. My thinking with these rules that I'm iffy on has always been to enable them and then remove them at the first sign of trouble, i.e. if any users report legit code that they're being prevented from writing. The nice thing about relaxing a rule is that you can do it in a minor version :)

Happy to go either way on this one. Anyone else have input?

@jprichardson

This comment has been minimized.

Copy link
Member

commented Jan 11, 2017

I use await inside of for-loops frequently. The common use case? Http requests. If it's all parallel, I could inadvertently blast the service and hit rate limitations.

@feross

This comment has been minimized.

Copy link
Member Author

commented Jan 11, 2017

Okay, that's enough for me. Let's skip this rule.

@feross feross closed this Jan 11, 2017

@tunnckoCore tunnckoCore referenced this issue Feb 21, 2017

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.