Skip to content

async keyword generates a different public API #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SeanFeldman opened this issue Feb 29, 2016 · 1 comment
Closed

async keyword generates a different public API #19

SeanFeldman opened this issue Feb 29, 2016 · 1 comment

Comments

@SeanFeldman
Copy link
Contributor

If understood correctly, async keyword is just a syntax sugar and shouldn't change public API.
Right now it does. Here's a repro:

public interface ITopology
{
    Task<bool> RunChecks();
}

public class A : ITopology 
{
    public Task<bool> RunChecks()
    {
        return Task.FromResult(true);
    }
}

public class B : ITopology
{
    public async Task<bool> RunChecks()
    {
        await Task.Delay(1); // mimicing some other call
        await Task.Delay(2); // mimicing some other call
        // logic to generate returned result based on invocations
        return true;
    }
}

Generate code is:

public class A : ITopology
{
        public System.Threading.Tasks.Task<bool> RunChecks() { }
}   

public class B : ITopology
{
        public async System.Threading.Tasks.Task<bool> RunChecks() { }
}
@danielmarbach
Copy link
Member

@SeanFeldman The async keyword should not be part of the public API at all. I submitted a PR #26

The async keyword is an implementation detail since it is just syntactic sugar. From an API perspective the following APIs are equivalent:

  • async void vs. void
  • async Task vs Task
  • async Task<T> vs Task<T>

From a behavior perspective you could argue that the runtime behavior from void to async void can change and therefore it could be a breaking change but from an API perspective both APIs are binary compatible. Since API approver's concern is only the public API the async keyword should be omitted. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants