-
Notifications
You must be signed in to change notification settings - Fork 752
refactor(general): avoid async method inside forEach (WIP)
#6264
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
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
forEachforEach
| { code: 'list.forEach(async (a) => await Promise.resolve(a * a))', errors: [errMsg] }, | ||
| { code: 'list.forEach(async (a: any) => console.log(x))', errors: [errMsg] }, | ||
| { code: 'list.forEach((a) => a.forEach(async (b) => a * b))', errors: [errMsg] }, | ||
| { code: 'list.forEach(async function () {})', errors: [errMsg] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about
const fn = async (item) => {}
list.forEach(fn)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See recent commits, also added a few more edge cases.
forEachforEach (WIP)
| 'aws-toolkits/no-console-log': 'error', | ||
| 'aws-toolkits/no-json-stringify-in-log': 'error', | ||
| 'aws-toolkits/no-printf-mismatch': 'error', | ||
| 'aws-toolkits/no-async-in-foreach': 'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just ban forEach? it is kind of pointless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think banning it out right has a few advantages. Additionally, determining if a function is async is definitely non-trivial. This work is moved to #6281
Problem
usage of an async function inside a
forEach, which is almost always not desired.forEachwill not await the results leading to race conditions and inconsistent orderings.Solution
feature/xbranches will not be squash-merged at release time.License: I confirm that my contribution is made under the terms of the Apache 2.0 license.