Re:Flutter: Futures, Isolates, Event Loop
by hbhakhra on Tuesday January 22, 2019 @03:28AM
(#18966848)
An async method can use await within it. A method can return a future but not be able to use the await keyword.
[ Parent
| on HN ]
Re:Flutter: Futures, Isolates, Event Loop
by ridiculous_fish on Tuesday January 22, 2019 @03:56PM
(#18972373)
What is the point of this restriction? Why not just allow all Future-returning functions to use await?
Re:Flutter: Futures, Isolates, Event Loop
by qqqwww on Tuesday January 22, 2019 @04:56PM
(#18972968)
Async methods also allow you to return values which will be returned as futures.
For example:
return 4;
If the function is marked async, the return value should be Future<int>.If you allow a non-async method use await, you get into this situation:
Future<int> foo(){
int result = await something ();
// How to return "result" and still make compiler happy?
}
Re:Flutter: Futures, Isolates, Event Loop
by ridiculous_fish on Wednesday January 23, 2019 @05:26AM
(#18977127)
Why not just some generic function T -> Future<T>?
It sounds like the async keyword allows for a particular implicit type conversion within the function body, but on return statements only. That's a pretty thin justification for a keyword.