Re:Flutter: Futures, Isolates, Event Loop
by ridiculous_fish on Tuesday January 22, 2019 @03:57PM
(#18972383)
But why do we need a new keyword to express this? Isn't the return type sufficient?
[ Parent
| on HN ]
Re:Flutter: Futures, Isolates, Event Loop
by krzat on Wednesday January 23, 2019 @03:50AM
(#18976726)
No, because you can write async functions without using async/await. Using callback for example:
Future<int> foo() {
return Future.delayed(Duration(seconds: 1)).then((x) => 1);
}
In this case there is no compiler magic needed. If you ask why async keyword is needed if we can just infer it from await inside the method body - probably only for readability.
Re:Flutter: Futures, Isolates, Event Loop
by ridiculous_fish on Wednesday January 23, 2019 @05:36AM
(#18977160)
async is part of the method signature, the public facing part of the method. But it controls an implementation detail, namely whether the function body may use await (as you say asynchronous functions are not required to use await).
I found a link [1] that described async as a compatibility affordance in C# 5: legacy code may use await as a variable name, so async opts into the contextual await keyword. But Dart doesn't have such legacy, so the keyword doesn't seem as well motivated.
https://blogs.msdn.microsoft.com/ericlippert/2010/11/11/asyn...