AsyncLock
AsyncLock copied to clipboard
AsyncLock is not 'await using' (IAsyncDisposable) compatible
Yes, of course, i known what can i do using(await lock.AsyncLock())
, but this is not entirely intuitive given the official syntax for IAsyncDisposable
If you don't mind, i can create a PR~
Hi @0xF6,
As you know, these are different semantics. await using
is to call IAsyncDisposable.DisposeAsync
asynchronously, but using (await foo.LockAsync())
acquires the lock asynchronously. It's also perfectly plausible to mix both (await using (await foo.LockAsync())
) to both acquire and dispose asynchronously.
If you're in an async context, you need to use await foo.LockAsync()
(regardless of whether you do using (await foo.LockAsync())
or you do await using (await foo.LockAsync())
) so that the event loop isn't blocked while the lock is acquired.
I'm not against implementing IAsyncDisposable
but there's no real need for it since there's no IO taking place during cleanup and no benefit over calling IDisposable.Dispose()
synchronously. We also want to make sure that invalid code (not invoking await
on LockAsync()
) doesn't accidentally compile.
Feel free to open a PR (with tests!) if you want to try that, but like I said, there are some issues that need to be kept in mind.
Feel free to open a PR (with tests!)
Oke, i'll do it on weekend~