NetCoreRateLimit/AsyncKeyLock/AsyncKeyLock.cs
/// <summary>
/// Gets the doorman for the specified key. If no such doorman exists, an unused doorman
/// is obtained from the pool (or a new one is allocated if the pool is empty), and it's
/// assigned to the requested key.
/// </summary>
/// <param name="key">The key for the desired doorman.</param>
/// <returns>The <see cref="Doorman"/>.</returns>
Gets the doorman for the specified key. If no such doorman exists, an unused doorman
is obtained from the pool (or a new one is allocated if the pool is empty), and it's
assigned to the requested key.
Gets the doorman for the specified key . If no such doorman exists an unused doorman is obtained from the pool ( or a new one is allocated if the pool is empty ) and it ' s assigned to the requested key .
private static AsyncKeyLockDoorman GetDoorman(string key)
        {
            AsyncKeyLockDoorman doorman;
            bool lockTaken = false;
            try
            {
                _spinLock.Enter(ref lockTaken);
                if (!Keys.TryGetValue(key, out doorman))
                {
                    doorman = (Pool.Count > 0) ? Pool.Pop() : new AsyncKeyLockDoorman(ReleaseDoorman);
                    doorman.Key = key;
                    Keys.Add(key, doorman);
                }
                doorman.RefCount++;
            }
            finally
            {
                if (lockTaken)
                {
                    _spinLock.Exit();
                }
            }
            return doorman;
        }
private static AsyncKeyLockDoorman GetDoorman ( string key ) { AsyncKeyLockDoorman doorman ; bool lockTaken = false ; try { _spinLock . Enter ( ref lockTaken ) ; if ( ! Keys . TryGetValue ( key , out doorman ) ) { doorman = ( Pool . Count > 0 ) ? Pool . Pop ( ) : new AsyncKeyLockDoorman ( ReleaseDoorman ) ; doorman . Key = key ; Keys . Add ( key , doorman ) ; } doorman . RefCount ++ ; } finally { if ( lockTaken ) { _spinLock . Exit ( ) ; } } return doorman ; }
Gets the doorman for the specified key.
Gets the doorman for the specified key .
None
key
string
The key for the desired doorman.
The key for the desired doorman .