Skip to content
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

Feature request: Prefer "await using" over "using" inside async methods #14

Open
devax opened this issue Feb 14, 2021 · 1 comment
Open

Comments

@devax
Copy link

devax commented Feb 14, 2021

Thank you for this great extension!

I have realized that I often miss the presence of IAsyncDisposable interfaces and there is no warning that indicates this. Example:

static async Task Main(string[] args)
{
    using SqlConnection connection = new SqlConnection();
    // Do something with connection
    // ...
}

This could (should?) be converted to:

static async Task Main(string[] args)
{
    await using SqlConnection connection = new SqlConnection();
    // Do something with connection
    // ...
}

Would it be a good idea to add a warning or an information, that await using could be used instead of using?

@semihokur
Copy link
Owner

Thanks for the suggestion. As far as I know, most DisposeAsync implementations are not truly asynchronous. There is actually a perf penalty when using DisposeAsync for those IAsyncDisposable interfaces. Because they fake async using thread-pool threads, we waste at least one thread blocking on I/O.

It is not possible to understand whether DisposeAsync operation is truly asynchronous and does not fake it. Sometimes, this even depends on the parameters of the constructor: new FileStream(..., useAsync: true)

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