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)); }
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); }
internal KeyedSemaphoreSlimHandle(KeyedSemaphoreSlim <TKey> keyedSemaphoreSlim, TKey key, KeyedSemaphoreSlimHandle <TKey> parentHandle) { this.keyedSemaphoreSlim = keyedSemaphoreSlim; this.key = key; this.parentHandle = parentHandle; }
public async Task <KeyedSemaphoreSlimHandle <TKey> > WaitAsync(TKey key, KeyedSemaphoreSlimHandle <TKey> parentHandle) { return(await WaitAsync(key, parentHandle, Timeout.InfiniteTimeSpan, CancellationToken.None)); }