Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • @Neil I probably got the point. An interface exposing methods returning Task or Task<T> is not a leaky abstraction per se, is simply a contract with a signature involving tasks. A method returning a Task or Task<T> does not imply having an async implementation (for instance if I create a completed task by using Task.CompletedTask I'm not doing an async implementation). Vice versa, the async implementation in C# requires that the return type of an async method must be of type Task or Task<T>. Put another way the only "leaky" aspect of my interface is the async suffix in names Commented Jan 14, 2019 at 15:22
  • @Neil actually there is a naming guideline which states that all async methods should have a name ending in "Async". But this does not imply that a method returning a Task or a Task<T> must be named with the Async suffix because it could be implemented by using no async calls. Commented Jan 14, 2019 at 15:25
  • 7
    I would argue the 'asyncness' of a method is indicated by the fact that it returns a Task. The guidelines for suffixing async methods with the word async was to distinguish between otherwise identical API calls (C# cant dispatch based on return type). At our company we've dropped it all together. Commented Jan 14, 2019 at 16:36
  • There are a number of answers and comments explaining why the asynchronous nature of the method is part of the abstraction. A more interesting question is how a language or programming API can separate the functionality of a method from how it is executed, to the point where we no longer need Task return values, or async markers? The functional programming people seem to have figured this out better. Consider how asynchronous methods are defined in F# and other languages. Commented Jan 14, 2019 at 21:49
  • 3
    :-) -> The "functional programming people" ha. Async is no more leaky than synchronous, it just seems that way because we're used to writing sync code by default. If we all coded async by default, a synchronous function might seem leaky. Commented Jan 15, 2019 at 21:28