Exemplo n.º 1
0
func newRatioController(tm timetools.TimeProvider, rampUp time.Duration) *ratioController {
	return &ratioController{
		duration: rampUp,
		tm:       tm,
		start:    tm.UtcNow(),
	}
}
Exemplo n.º 2
0
// newTokenBucket crates a `tokenBucket` instance for the specified `Rate`.
func newTokenBucket(rate *rate, clock timetools.TimeProvider) *tokenBucket {
	return &tokenBucket{
		period:          rate.period,
		timePerToken:    time.Duration(int64(rate.period) / rate.average),
		burst:           rate.burst,
		clock:           clock,
		lastRefresh:     clock.UtcNow(),
		availableTokens: rate.burst,
	}
}