3 ms·
I disagree. What you're arguing, in effect, is that async/await is bad because you should handle asynchronous APIs by taking a synchronous API and running it in
by jcranmer 12y ago
I disagree. What you're arguing, in effect, is that async/await is bad because you should handle asynchronous APIs by taking a synchronous API and running it in a different thread, which experience has generally shown to be a recipe for buggy code, inefficient code, or most likely both.
The underlying idea behind async/await is that synchronous methods shouldn't exist in the first place--you'd only have the asynchronous API. Async/await enhances that model by turning the promises' functional interface (which requires interesting binding to handle loops/recursion) back into an imperative control interface.
- PopsiclePete 12y agoNot true from what I've seen Every C# library with support for async/await has synchronous versions of those same methods. In fact, Microsoft's own documentation recommends appending "Async" to the method name for precisely that reason - to distinguish an async method from a sync method. Furthermore, "asynchronous" code doesn't need separate threads. A scheduler and green threads is more than enough. Have you seen Go? You should take a look at it. It makes writing concurrent code basically trivial, using "green" threads and channels and a neat little "select" statement.
- giulianob 12y agoThey only support both because most libraries still support older version of .NET If they were to support only .NET 4.5 or higher, then you can just call any async method in a sync manner simply by doing httpClient.GetAsync(...).Result async/await in C# is a beautiful thing.