func (q *RateLimitedTimedQueue) SwapLimiter(newQPS float32) {
	q.limiterLock.Lock()
	defer q.limiterLock.Unlock()
	if q.limiter.QPS() == newQPS {
		return
	}
	var newLimiter flowcontrol.RateLimiter
	if newQPS <= 0 {
		newLimiter = flowcontrol.NewFakeNeverRateLimiter()
	} else {
		newLimiter = flowcontrol.NewTokenBucketRateLimiter(newQPS, EvictionRateLimiterBurst)

		// If we're currently waiting on limiter, we drain the new one - this is a good approach when Burst value is 1
		// TODO: figure out if we need to support higher Burst values and decide on the drain logic, should we keep:
		// - saturation (percentage of used tokens)
		// - number of used tokens
		// - number of available tokens
		// - something else
		if q.limiter.TryAccept() == false {
			newLimiter.TryAccept()
		}
	}
	q.limiter.Stop()
	q.limiter = newLimiter
}
// SwapLimiter safely swaps current limiter for this queue with the
// passed one if capacities or qps's differ.
SwapLimiter safely swaps current limiter for this queue with the
passed one if capacities or qps's differ.
// SwapLimiter safely swaps current limiter for this queue with the // passed one if capacities or qps ' s differ .
func (q *RateLimitedTimedQueue) SwapLimiter(newQPS float32) {
	q.limiterLock.Lock()
	defer q.limiterLock.Unlock()
	if q.limiter.QPS() == newQPS {
		return
	}
	var newLimiter flowcontrol.RateLimiter
	if newQPS <= 0 {
		newLimiter = flowcontrol.NewFakeNeverRateLimiter()
	} else {
		newLimiter = flowcontrol.NewTokenBucketRateLimiter(newQPS, EvictionRateLimiterBurst)
		if q.limiter.TryAccept() == false {
			newLimiter.TryAccept()
		}
	}
	q.limiter.Stop()
	q.limiter = newLimiter
}
func ( q * RateLimitedTimedQueue ) SwapLimiter ( newQPS float32 ) { q . limiterLock . Lock ( ) defer q . limiterLock . Unlock ( ) if q . limiter . QPS ( ) == newQPS { return } var newLimiter flowcontrol . RateLimiter if newQPS <= 0 { newLimiter = flowcontrol . NewFakeNeverRateLimiter ( ) } else { newLimiter = flowcontrol . NewTokenBucketRateLimiter ( newQPS , EvictionRateLimiterBurst ) if q . limiter . TryAccept ( ) == false { newLimiter . TryAccept ( ) } } q . limiter . Stop ( ) q . limiter = newLimiter }
SwapLimiter safely swaps current limiter for this queue with the
passed one if capacities or qps's differ.
SwapLimiter safely swaps current limiter for this queue with the passed one if capacities or qps ' s differ .
// If we're currently waiting on limiter, we drain the new one - this is a good approach when Burst value is 1 // TODO: figure out if we need to support higher Burst values and decide on the drain logic, should we keep: // - saturation (percentage of used tokens) // - number of used tokens // - number of available tokens // - something else