mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 01:33:03 +08:00
27 lines
557 B
C#
27 lines
557 B
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MQTTnet.Internal
|
|
{
|
|
public sealed class AsyncLock : IDisposable
|
|
{
|
|
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
|
|
|
|
public Task EnterAsync(CancellationToken cancellationToken)
|
|
{
|
|
return _semaphore.WaitAsync(cancellationToken);
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
_semaphore.Release();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_semaphore?.Dispose();
|
|
}
|
|
}
|
|
}
|