I saw many people's code use async
keyword in a function without an await
keyword in the function body. Even some official flutter example code do this. I have no idea why. What is the point? Is this a mistake or having a purpose?
Normally, I just remove the async
keyword from those code and everything will run without any problems. Can some dart expert clarify that if there is a purpose for a function which has the async
keyword but NO await
keyword? Or is this just their mistake?
async
is sometimes used to simplify code.
Here are some examples:
Future<int> f1() async => 1;
Future<int> f1() => Future.value(1);
Future<void> f2() async {
throw Error();
}
Future<void> f2() {
return Future.error(Error());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With