wabbajack/Wabbajack.Common/AsyncLock.cs
2021-09-27 06:42:46 -06:00

18 lines
418 B
C#

using System;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
namespace Wabbajack.Common
{
public class AsyncLock
{
private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
public async Task<IDisposable> WaitAsync()
{
await _lock.WaitAsync();
return Disposable.Create(() => _lock.Release());
}
}
}