-
Notifications
You must be signed in to change notification settings - Fork 240
Composite locks #248
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
base: master
Are you sure you want to change the base?
Composite locks #248
Conversation
…istributed synchronization handles
madelson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @moeen ! This is off to a great start!
src/DistributedLock.Core/CompositeDistributedSynchronizationHandle.cs
Outdated
Show resolved
Hide resolved
src/DistributedLock.Core/DistributedUpgradeableReaderWriterLockProviderExtensions.cs
Outdated
Show resolved
Hide resolved
src/DistributedLock.Core/DistributedUpgradeableReaderWriterLockProviderExtensions.cs
Outdated
Show resolved
Hide resolved
src/DistributedLock.Core/CompositeDistributedSynchronizationHandle.cs
Outdated
Show resolved
Hide resolved
src/DistributedLock.Core/CompositeDistributedSynchronizationHandle.cs
Outdated
Show resolved
Hide resolved
src/DistributedLock.Core/CompositeDistributedSynchronizationHandle.cs
Outdated
Show resolved
Hide resolved
| /// </summary> | ||
| {{interfaceName}} {{createMethodName}}(string name{{(interfaceName.Contains("Semaphore") ? ", int maxCount" : string.Empty)}}); | ||
| } | ||
| """; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the use of """ strings here, but let's indent less:
var providerInterfaceCode = $$"""
...
""";
Please address throughout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated code looks well indented. The raw string literals use aligned indentation for readability in the generator, the compiler strips the common leading whitespace anyway.
Happy to adjust if you prefer less indentation!
|
Is there a better alternative to this PR? |
|
Hi! Sorry for the delay - I was busy and totally forgot about this. I've now resolved all the comments and added the tests as discussed. The PR should be ready for another review. Thanks for your patience! Sample use with the Redis Provider: var connection = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
var provider = new RedisDistributedSynchronizationProvider(connection.GetDatabase());
const string FromAccount = "account:alice";
const string ToAccount = "account:bob";
const decimal Amount = 100m;
var accounts = new[] { FromAccount, ToAccount };
await using (var handle = await provider.TryAcquireAllLocksAsync(accounts, TimeSpan.FromSeconds(30)))
{
if (handle != null)
{
Console.WriteLine($"Transferring ${Amount} from {FromAccount} to {ToAccount}");
await Task.Delay(1000);
Console.WriteLine("Transfer completed successfully");
}
else
{
Console.WriteLine("Failed to acquire locks - transfer aborted");
}
}
await connection.CloseAsync(); |
|
@moeen Dear Boss, could you please merge the code and provide the nget feature? I really need this functionality—thank you very much! |
This pull request introduces new composite lock methods for various lock types via code generation.
Auto Generated Codes
src/DistributedLock.Core/DistributedLockProviderExtensions.cssrc/DistributedLock.Core/DistributedReaderWriterLockProviderExtensions.cssrc/DistributedLock.Core/DistributedSemaphoreProviderExtensions.cssrc/DistributedLock.Core/DistributedUpgradeableReaderWriterLockProviderExtensions.cs