A naive implementation of async lock
Behind the scenes the implementation uses SemaphoreSlim to do all the heavy lifting which already has a support for async/await.
You would normally use AsyncLock within a “using” statement. To keep the implementation as simple as possible I do not use any cancellation tokens for any of the operations.
private readonly AsyncLock _lock = new AsyncLock();
public async Task DoSomethingAsync()
using (await _lock.EnterAsync())
Leave a Reply