chore: continue porting code and adding test coverage

This commit is contained in:
Stevan Freeborn
2025-05-08 01:36:04 -05:00
parent 3f4ab165ce
commit 9f35394528
12 changed files with 305 additions and 9 deletions
@@ -0,0 +1,24 @@
namespace StevesBot.Worker.Threading;
internal sealed class AsyncLock : IAsyncLock
{
private readonly SemaphoreSlim _semaphore = new(1, 1);
private bool _disposed;
public async Task<IDisposable> LockAsync(CancellationToken cancellationToken = default)
{
await _semaphore.WaitAsync(cancellationToken);
return new LockReleaser(_semaphore);
}
public void Dispose()
{
if (_disposed)
{
return;
}
_semaphore.Dispose();
_disposed = true;
}
}