public bool TryAccept(string id, ThrottleParams throttleParams, out WaitOnFailOptions waitOnFailOptions) { var count = _count; // Exit if count == MaxValue as incrementing would overflow. while (count < _max && count != int.MaxValue) { var prev = Interlocked.CompareExchange(ref _count, count + 1, count); if (prev == count) { waitOnFailOptions = default(WaitOnFailOptions); return(true); } // Another thread changed the count before us. Try again with the new counter value. count = prev; } waitOnFailOptions = this.WaitOnFailOptions; return(false); }
public LimitConcurrentQueueManager(int concurrentRequests, TimeSpan waitOnFailTimeout) { this._max = concurrentRequests; this.WaitOnFailOptions = new WaitOnFailOptions(waitOnFailTimeout); }