3 ms·
An async method can use await within it. A method can return a future but not be able to use the await keyword.
by hbhakhra 8y ago
An async method can use await within it. A method can return a future but not be able to use the await keyword.
- ridiculous_fish 8y agoWhat is the point of this restriction? Why not just allow all Future-returning functions to use await?
- qqqwww 8y agoAsync 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? }
- ridiculous_fish 8y agoWhy 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.