wabbajack/Wabbajack.Common/AsyncLock.cs

17 lines
366 B
C#
Raw Normal View History

using System;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.Common;
public class AsyncLock
{
2021-10-23 16:51:17 +00:00
private readonly SemaphoreSlim _lock = new(1, 1);
2021-10-23 16:51:17 +00:00
public async Task<IDisposable> WaitAsync()
{
await _lock.WaitAsync();
return Disposable.Create(() => _lock.Release());
}
2021-10-23 16:51:17 +00:00
}