Ejemplo n.º 1
0
        public async Task <KeyedSemaphoreSlimHandle <TKey> > WaitAsync(TKey key, KeyedSemaphoreSlimHandle <TKey> parentHandle, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var sync = RegisterKey(key);

            await sync.WaitAsync(timeout, cancellationToken);

            return(new KeyedSemaphoreSlimHandle <TKey>(this, key, parentHandle));
        }
Ejemplo n.º 2
0
        public static async Task <KeyedSemaphoreSlimHandle <TKey> > WaitAsync <TKey>(this KeyedSemaphoreSlim <TKey> keyedSemaphoreSlim, IEnumerable <TKey> keys,
                                                                                     TimeSpan timeout, CancellationToken cancellationToken)
        {
            KeyedSemaphoreSlimHandle <TKey> handle = null;

            try
            {
                foreach (var key in keys)
                {
                    handle = await keyedSemaphoreSlim.WaitAsync(key, handle, timeout, cancellationToken);
                }
            }
            catch (Exception e)
            {
                handle?.Dispose();
                throw e;
            }

            return(handle);
        }
Ejemplo n.º 3
0
 internal KeyedSemaphoreSlimHandle(KeyedSemaphoreSlim <TKey> keyedSemaphoreSlim, TKey key, KeyedSemaphoreSlimHandle <TKey> parentHandle)
 {
     this.keyedSemaphoreSlim = keyedSemaphoreSlim;
     this.key          = key;
     this.parentHandle = parentHandle;
 }
Ejemplo n.º 4
0
 public async Task <KeyedSemaphoreSlimHandle <TKey> > WaitAsync(TKey key, KeyedSemaphoreSlimHandle <TKey> parentHandle)
 {
     return(await WaitAsync(key, parentHandle, Timeout.InfiniteTimeSpan, CancellationToken.None));
 }