-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Idea: lint when passing async functions into forEach #57677
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
Comments
Async functions will be executed synchronously in Dart 2, FWIW. |
Good point! This lint would definitely have more impact in Dart 1. |
See also #57769 Should we merge these issues? |
I see this confusion all the time on StackOverflow. It would be nice if there were a warning about passing |
@jamesderlin: the next time you see this come up on SO, could you add a link? That'd be great for motivation. Thanks! |
Amazing. Thank you! |
I recently ran into a few instances of code that used the following:
The intended behavior in at least one of the cases was to wait for all of the
await
s to be run before proceeding, which can be done viaFuture.forEach
or a for loop withawaits
.Even if the intended behavior is what is actually happening, it might not be immediately obvious to someone unfamiliar with how
async
functions are executed in Dart 1.x.The first example would be avoided by using the prefer_foreach rule (unless a tearoff were passed in instead), but the second would not. Still, for the first example, it might be good to have a more specific lint to catch this case.
Are
Iterable.forEach
/Map.forEach
common-enough special cases where using async functions should result in a lint?Another idea, though it would have far more impact and may be too noisy, would be to lint when an async function is being used where a
void
function is accepted.The text was updated successfully, but these errors were encountered: