Skip to content

Commit

Permalink
AccessLockFactory accepts a key when creating primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
cnshenj committed Jul 29, 2022
1 parent 102d005 commit f668e51
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Authors>SidekickNet</Authors>
<Description>Provides Azure related utilities for ASP.NET Core.</Description>
<Copyright>Copyright (c) Zhang Shen. All rights reserved.</Copyright>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/cnshenj/SidekickNet.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/cnshenj/SidekickNet</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Utilities.AspNetCore/Utilities.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Authors>SidekickNet</Authors>
<Description>Provides utility methods for ASP.NET Core.</Description>
<Copyright>Copyright (c) Zhang Shen. All rights reserved.</Copyright>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/cnshenj/SidekickNet.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/cnshenj/SidekickNet</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Utilities.Azure/Utilities.Azure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Authors>SidekickNet</Authors>
<Description>Provides utility methods for Azure resources.</Description>
<Copyright>Copyright (c) Zhang Shen. All rights reserved.</Copyright>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/cnshenj/SidekickNet.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/cnshenj/SidekickNet</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Utilities.Json/Utilities.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Authors>SidekickNet</Authors>
<Description>Provides utility methods for JSON.</Description>
<Copyright>Copyright (c) Zhang Shen. All rights reserved.</Copyright>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/cnshenj/SidekickNet.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/cnshenj/SidekickNet</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Utilities.MessagePack/Utilities.MessagePack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Authors>SidekickNet</Authors>
<Description>Provides utility methods for MessagePack.</Description>
<Copyright>Copyright (c) Zhang Shen. All rights reserved.</Copyright>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/cnshenj/SidekickNet.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/cnshenj/SidekickNet</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Utilities/InterlockedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class InterlockedDictionary<TKey, TValue> : Dictionary<TKey, TValue>
/// <param name="lockTimeout">A <see cref="TimeSpan"/> that represents the time period to wait to acquire access locks.</param>
public InterlockedDictionary(TimeSpan? lockTimeout = default)
{
this.lockFactory = new AccessLockFactory<TKey>(() => new LocalSemaphore(1, 1), lockTimeout);
this.lockFactory = new AccessLockFactory<TKey>(_ => new LocalSemaphore(1, 1), lockTimeout);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Utilities/Synchronization/AccessLockFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AccessLockFactory<TKey>
{
private readonly ConcurrentDictionary<TKey, ISynchronizationPrimitive> primitives = new();

private readonly Func<ISynchronizationPrimitive> primitiveFactory;
private readonly Func<TKey, ISynchronizationPrimitive> primitiveFactory;

private readonly TimeSpan timeout;

Expand All @@ -26,7 +26,7 @@ public class AccessLockFactory<TKey>
/// </summary>
/// <param name="primitiveFactory">The function that generate synchronization primitives.</param>
/// <param name="timeout">A <see cref="TimeSpan"/> that represents the default time period to wait to acquire access locks.</param>
public AccessLockFactory(Func<ISynchronizationPrimitive> primitiveFactory, TimeSpan? timeout = default)
public AccessLockFactory(Func<TKey, ISynchronizationPrimitive> primitiveFactory, TimeSpan? timeout = default)
{
this.primitiveFactory = primitiveFactory ?? throw new ArgumentNullException(nameof(primitiveFactory));
this.timeout = timeout ?? AccessLock.Indefinite;
Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task<AccessLock> GetLockAsync(TKey key, TimeSpan? timeout = default

private AccessLock CreateLock(TKey key)
{
var primitive = this.primitives.GetOrAdd(key, _ => this.primitiveFactory());
var primitive = this.primitives.GetOrAdd(key, this.primitiveFactory);
return new AccessLock(primitive);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Utilities/Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Authors>SidekickNet</Authors>
<Description>Provides utility methods for .NET objects, e.g. strings, collections.</Description>
<Copyright>Copyright (c) Zhang Shen. All rights reserved.</Copyright>
<Version>0.3.5</Version>
<Version>0.3.6</Version>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://github.com/cnshenj/SidekickNet.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/cnshenj/SidekickNet</PackageProjectUrl>
Expand Down

0 comments on commit f668e51

Please sign in to comment.