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

How to dispose SqlDistributedLock asynchronously? #20

Closed
clement911 opened this issue Nov 2, 2018 · 2 comments
Closed

How to dispose SqlDistributedLock asynchronously? #20

clement911 opened this issue Nov 2, 2018 · 2 comments
Milestone

Comments

@clement911
Copy link

The using pattern is nice and reads very well.

However, the implicit call to Dispose is doing a synchronous db call and blocking the calling thread so I'd love to see an option to dispose asynchronously, even if it means I can't use the using keyword in my calling code.

I guess SqlDistributedLock .TryAcquireAsync could return an interface like this:

IAsyncDisposable : IDisposable
{
    Task DisposeAsync();
}

What do you think?

@madelson
Copy link
Owner

madelson commented Nov 2, 2018

Hi @clement911 thanks for the suggestion. I agree that this is a good idea. A few thoughts:

  • Changing this would be a binary breaking change, so we would have to do it as part of a 2.0 release
  • It looks like .NET Core is working on a standard IAsyncDisposable interface for this (https://github.com/dotnet/corefx/issues/32640), so I would want to wait for that to be released and understand the implications of it (e .g. can you use it in a using block?) before building this.
  • Finally, some lock releases can't benefit from async (e. g. transaction-based locks release with SqlTransaction.Dispose(), which isn't async. That said, (a) maybe this will change when IAsyncDisposable comes out and (b) it doesn't stop us from implementing the interface for the cases where we will get the benefit.

@madelson madelson added this to the 2.0 milestone Nov 2, 2018
@clement911
Copy link
Author

Makes sense. Looking forward to IAsyncDisposable!

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

No branches or pull requests

2 participants