{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/4166","labels_url":"https://api.github.com/repos/eslint/eslint/issues/4166/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/4166/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/4166/events","html_url":"https://github.com/eslint/eslint/issues/4166","id":111883291,"number":4166,"title":"Proposed rule: no-await-in-loop","user":{"login":"nmote","id":7988361,"avatar_url":"https://avatars.githubusercontent.com/u/7988361?v=3","gravatar_id":"","url":"https://api.github.com/users/nmote","html_url":"https://github.com/nmote","followers_url":"https://api.github.com/users/nmote/followers","following_url":"https://api.github.com/users/nmote/following{/other_user}","gists_url":"https://api.github.com/users/nmote/gists{/gist_id}","starred_url":"https://api.github.com/users/nmote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmote/subscriptions","organizations_url":"https://api.github.com/users/nmote/orgs","repos_url":"https://api.github.com/users/nmote/repos","events_url":"https://api.github.com/users/nmote/events{/privacy}","received_events_url":"https://api.github.com/users/nmote/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/triage","name":"triage","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-16T18:18:18Z","updated_at":"2015-10-16T18:18:18Z","closed_at":null,"body":"**When does this rule warn?**\r\n\r\nThis rule warns when a developer uses `await` inside of a loop. Doing so means that each loop iteration will run in serial, when often the desired behavior is to dispatch a bunch of asynchronous operations and then await on the result as a whole, using `Promise.all`.\r\n\r\nOccasionally, awaiting inside a loop actually is desirable. In cases like those, \r\n\r\nHere is an example:\r\n\r\n```js\r\nasync foo() {\r\n  for (const bar of baz) {\r\n    await(bar);\r\n  }\r\n}\r\n```\r\n\r\nHere is my proposed warning:\r\n\r\n'Avoid using await inside a loop. Consider refactoring to use Promise.all. If you are sure you want to do this, add `// eslint-disable-line no-await-in-loop` at the end of this line.'\r\n\r\n**Is this rule preventing an error or is it stylistic?**\r\n\r\nThis rule prevents an error. Needlessly awaiting inside of a loop can have serious performance implications.\r\n\r\n**Why is this rule a candidate for inclusion instead of creating a custom rule?**\r\n\r\nUsing `await` inside of a loop is a bad pattern no matter what codebase you are operating in. There are occasional places where it is desirable but it is almost always a sign that you have done something wrong.\r\n\r\nMy only concern is that this rule will not operate with the `eslint` frontend -- to my knowledge, it has not implemented async/await parsing yet. Therefore it could be confusing to have a rule built-in to `eslint` that requires its users to use `babel-eslint`.\r\n\r\n**Are you willing to create the rule yourself?**\r\n\r\nYes. I have already written the [first version](https://github.com/facebook/nuclide/blob/4c83f145469ef52b384839ce03e8913ba76ae9f0/scripts/lib/eslint/eslint_rules/no-await-in-loop.js)."},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/148790370","html_url":"https://github.com/eslint/eslint/issues/4166#issuecomment-148790370","issue_url":"https://api.github.com/repos/eslint/eslint/issues/4166","id":148790370,"user":{"login":"eslintbot","id":13383618,"avatar_url":"https://avatars.githubusercontent.com/u/13383618?v=3","gravatar_id":"","url":"https://api.github.com/users/eslintbot","html_url":"https://github.com/eslintbot","followers_url":"https://api.github.com/users/eslintbot/followers","following_url":"https://api.github.com/users/eslintbot/following{/other_user}","gists_url":"https://api.github.com/users/eslintbot/gists{/gist_id}","starred_url":"https://api.github.com/users/eslintbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eslintbot/subscriptions","organizations_url":"https://api.github.com/users/eslintbot/orgs","repos_url":"https://api.github.com/users/eslintbot/repos","events_url":"https://api.github.com/users/eslintbot/events{/privacy}","received_events_url":"https://api.github.com/users/eslintbot/received_events","type":"User","site_admin":false},"created_at":"2015-10-16T18:18:18Z","updated_at":"2015-10-16T18:18:18Z","body":"Thanks for the issue! If you're reporting a bug, please be sure to include:\n\n1. The version of ESLint you are using (run `eslint -v`)\n2. What you did (the source code and ESLint configuration)\n3. The actual ESLint output complete with numbers\n4. What you expected to happen instead\n\nRequesting a new rule? Please see [Proposing a New Rule](http://eslint.org/docs/developer-guide/contributing/new-rules) for instructions."}}