-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Await void #28305
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
I guess the static behavior of That said, if the static type of the expression is void, then it should probably be a strong mode error - you are not allowed to "use" void results. |
I think awaiting a non-future is likely to be an error, but not always one. It is useful to be able to write code that is "polymorphic over asynchrony". You have some object that may or may not be a future. It's handy to be able to reliably I don't think that makes sense with
+1. |
There is a linter rule http://dart-lang.github.io/linter/lints/await_only_futures.html |
@lrhn is this captured by the category 1 or 3 errors that we have discussed? |
This would be a category 1 error - an expression of type That said, I think I was actually considering allowing |
I think the consistent approach would be to allow The lint that Günter mentioned could then optionally be used by developers to avoid all cases of "don't await an immediate", no matter whether it returns a useful value or not. |
It's a case of "allow only the useful" vs. "disallow only the problematic", and we haven't decided exactly on which approach we'll favor. I'm leaning towards disallowing it, although not heavily. Since its not useful, nobody will be hurt by that. I don't buy "consistency" as an argument for that many things when it comes to |
OK, I'll try:
OK, it works! Then we should also ban (or allow both the value- and the void-variant, of course) |
To be honest, I tend to agree. In Dart 1, we don't generally let types decide program validity, so it would at most be a warning. |
+1 |
Note that import 'dart:async';
void main() async {
print("a");
await wait(); // waits 5 seconds
print("b");
}
void wait() async {
await Future.delayed(Duration(seconds: 5));
} |
Yes, we don't have any items on the positive list matching This makes sense, too, because the expression could evaluate to a value of type Given that we have explicitly stated (in the feature spec) that |
This code doesn't contain any static warnings:
Should it? It seems like code that is awaiting an immediate value is likely to be an error. Code that is awaiting
void
is really likely to be an error.This cropped in internally because someone was doing:
Instead of using
forEach()
they should have usedmap()
.cc @floitschG @eernstg @lrhn @leafpetersen @bwilkerson
The text was updated successfully, but these errors were encountered: