diff --git a/src/Imazen.Common/Concurrency/BasicAsyncLock.cs b/src/Imazen.Common/Concurrency/BasicAsyncLock.cs index 403919c..cab7d97 100644 --- a/src/Imazen.Common/Concurrency/BasicAsyncLock.cs +++ b/src/Imazen.Common/Concurrency/BasicAsyncLock.cs @@ -10,18 +10,10 @@ public BasicAsyncLock() releaser = Task.FromResult((IDisposable)new Releaser(this)); } - public Task LockAsync(CancellationToken cancellationToken = default) + public Task LockAsync() => LockAsyncWithTimeout(Timeout.Infinite, CancellationToken.None); + public Task LockAsyncWithTimeout(int timeoutMilliseconds = Timeout.Infinite, CancellationToken cancellationToken = default) { - var wait = semaphore.WaitAsync(cancellationToken); - return wait.IsCompleted ? - releaser : - wait.ContinueWith((_, state) => (IDisposable)state!, - releaser.Result, CancellationToken.None, - TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); - } - public Task LockAsync(TimeSpan timeout, CancellationToken cancellationToken = default) - { - var wait = semaphore.WaitAsync(timeout, cancellationToken); + var wait = semaphore.WaitAsync(timeoutMilliseconds, cancellationToken); return wait.IsCompleted ? releaser : wait.ContinueWith((_, state) => (IDisposable)state!,