Closed Stroniax closed 3 years ago
Sure, this should be possible. We’re already supporting CancellationToken
for the async
code, so this would look very similar. Feel free to open a PR.
This is included in today's non-preview AsyncLock 3.2.0 release on NuGet. @Stroniax you are mentioned in the release notes for your contribution - much appreciated!
Since the synchronous Lock method is calling
_parent.Wait()
, which accepts a cancellation token, please allow a cancellation token to be provided to the Lock() method.https://github.com/neosmart/AsyncLock/blob/653b788cdd8a17c6e3615a5675b57093ffb01454/AsyncLock/AsyncLock.cs#L81-L89
https://github.com/neosmart/AsyncLock/blob/653b788cdd8a17c6e3615a5675b57093ffb01454/AsyncLock/AsyncLock.cs#L205-L212
I haven't looked very much at the code, I imagine proper disposal may also be required if the cancellation is requested.