-
Notifications
You must be signed in to change notification settings - Fork 208
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
Why allow async function, with no await or future? #4148
Comments
This is impossible, all async functions always return futures. Even if they are typed
That function isn't valid, it is an error
Sometimes you want a function to have an async return type even though it doesn't do anything async today. Maybe it is an override of an async method, or you want to allow overrides to be async, or you want to change your implementation to be async later on. The |
What @jakemac53 says. So don't do that. |
Closing this because I think the question was answered. |
Apologies. My example was bad. This is precisely the case I was referring to. I guess the answer would still be the same then, @munificent ? I also don't think it should be disallowed, but sure would be nice to have my linter catch it (often times it gets missed when modifying code that previously required async) |
There is a avoid_void_async https://dart.dev/tools/linter-rules/avoid_void_async which is similar. |
That's actually really helpful for my case. Thanks for sharing. Can discuss with my team if we want to enforce it. That rule will at least make it more explicit, and likely not missed 🤣 |
I have a pretty simple question (maybe it has a pretty simple answer?).
Is there ever a reason for a function to be async, when it doesn't await nor return a future?
For example, let's say I have this:
Shouldn't it be a default linting rule that the
async
in this case be noted as "unnecessary"?It's entirely possible I am missing something, but at least 3-4 times this week, I have encountered this exact case, where we don't want the function to be async, there's no reason for it. Given how good the Dart linting is, it's shocking that this doesn't get called out. But again, does have me wondering if there's an actual legitimate case for this 🤔
This may be loosely related to the discussion here: #3571
The text was updated successfully, but these errors were encountered: