Catel.Threading.AsyncLock.LockAsync C# (CSharp) Method

LockAsync() public method

Asynchronously acquires the lock. Returns a disposable that releases the lock when disposed.
public LockAsync ( CancellationToken cancellationToken ) : AwaitableDisposable
cancellationToken System.Threading.CancellationToken The cancellation token used to cancel the lock. If this is already set, then this method will attempt to take the lock immediately (succeeding if the lock is currently available).
return AwaitableDisposable
        public AwaitableDisposable<IDisposable> LockAsync(CancellationToken cancellationToken)
        {
            Task<IDisposable> ret;

            lock (_mutex)
            {
                if (!_taken)
                {
                    // If the lock is available, take it immediately.
                    _taken = true;
                    ret = _cachedKeyTask;
                }
                else
                {
                    // Wait for the lock to become available or cancellation.
                    ret = _queue.Enqueue(_mutex, cancellationToken);
                }

                //Enlightenment.Trace.AsyncLock_TrackLock(this, ret);
            }

            return new AwaitableDisposable<IDisposable>(ret);
        }

Same methods

AsyncLock::LockAsync ( ) : AwaitableDisposable