initial commit
This commit is contained in:
29
BlueMine/Redmine/AsyncLock.cs
Normal file
29
BlueMine/Redmine/AsyncLock.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace BlueMine.Redmine
|
||||
{
|
||||
public class AsyncLock
|
||||
{
|
||||
private readonly SemaphoreSlim _semaphore = new(1, 1);
|
||||
|
||||
public async Task<IDisposable> LockAsync()
|
||||
{
|
||||
await _semaphore.WaitAsync();
|
||||
return new Disposable(() => _semaphore.Release());
|
||||
}
|
||||
|
||||
private class Disposable : IDisposable
|
||||
{
|
||||
private readonly Action _action;
|
||||
|
||||
public Disposable(Action action)
|
||||
{
|
||||
_action = action;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user