mirror of https://github.com/abpframework/abp.git
7 changed files with 91 additions and 14 deletions
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Medallion.Threading; |
|||
|
|||
namespace Volo.Abp.DistributedLocking |
|||
{ |
|||
public static class AbpDistributedLockHandleExtensions |
|||
{ |
|||
public static IDistributedSynchronizationHandle ToDistributedSynchronizationHandle( |
|||
this IAbpDistributedLockHandle handle) |
|||
{ |
|||
return handle.As<MedallionAbpDistributedLockHandle>().Handle; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Medallion.Threading; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.DistributedLocking |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class MedallionAbpDistributedLock : IAbpDistributedLock, ITransientDependency |
|||
{ |
|||
protected IDistributedLockProvider DistributedLockProvider { get; } |
|||
|
|||
public MedallionAbpDistributedLock(IDistributedLockProvider distributedLockProvider) |
|||
{ |
|||
DistributedLockProvider = distributedLockProvider; |
|||
} |
|||
|
|||
public async Task<IAbpDistributedLockHandle> TryAcquireAsync( |
|||
string name, |
|||
TimeSpan timeout = default, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(name, nameof(name)); |
|||
|
|||
var handle = await DistributedLockProvider.TryAcquireLockAsync(name, timeout, cancellationToken); |
|||
if (handle == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return new MedallionAbpDistributedLockHandle(handle); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System.Threading.Tasks; |
|||
using Medallion.Threading; |
|||
|
|||
namespace Volo.Abp.DistributedLocking |
|||
{ |
|||
public class MedallionAbpDistributedLockHandle : IAbpDistributedLockHandle |
|||
{ |
|||
public IDistributedSynchronizationHandle Handle { get; } |
|||
|
|||
public MedallionAbpDistributedLockHandle(IDistributedSynchronizationHandle handle) |
|||
{ |
|||
Handle = handle; |
|||
} |
|||
|
|||
public ValueTask DisposeAsync() |
|||
{ |
|||
return Handle.DisposeAsync(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue