Documentation ¶
Index ¶
Constants ¶
const ( DefaultMaxStep = 5 * time.Hour DefaultDuration = 3 * time.Second DefaultFactor = 1.8 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LimitedBackoff ¶
type LimitedBackoff struct {
// contains filtered or unexported fields
}
LimitedBackoff provides backoff rate limiter with limit functionality, when the limit is reached it stops to calculate next backoff.
func NewExponentialLimitedBackoffWithClock ¶
func NewExponentialLimitedBackoffWithClock(limit time.Duration, clk clock.Clock) LimitedBackoff
func (*LimitedBackoff) Ready ¶
func (l *LimitedBackoff) Ready() bool
Ready return true when the current backoff end-time passed and limit is not reached.
type LimitedBackoffCreator ¶
type LimitedBackoffCreator struct {
// contains filtered or unexported fields
}
func NewExponentialLimitedBackoffCreator ¶
func NewExponentialLimitedBackoffCreator() LimitedBackoffCreator
func (*LimitedBackoffCreator) New ¶
func (l *LimitedBackoffCreator) New() LimitedBackoff
type RateLimitedExecutor ¶
type RateLimitedExecutor struct {
// contains filtered or unexported fields
}
RateLimitedExecutor provides self-contained entity that enables rate-limiting a given func execution (e.g: with an exponential backoff) without blocking the goroutine it runs on.
func NewRateLimitedExecutor ¶
func NewRateLimitedExecutor(rateLimiter rateLimiter) *RateLimitedExecutor
func (*RateLimitedExecutor) Exec ¶
func (c *RateLimitedExecutor) Exec(command func() error) error
Exec will execute the given func when the underlying rate-limiter is not blocking; rate-limiter's end time is passed and limit is not reached.
type RateLimitedExecutorPool ¶
type RateLimitedExecutorPool struct {
// contains filtered or unexported fields
}
RateLimitedExecutorPool aggregates RateLimiterExecutor's by keys, each key element is self-contained and have its own rate-limiter. Each element rate-limiter is created by the given creator.
func NewRateLimitedExecutorPool ¶
func NewRateLimitedExecutorPool(creator LimitedBackoffCreator) *RateLimitedExecutorPool
func (*RateLimitedExecutorPool) Delete ¶
func (c *RateLimitedExecutorPool) Delete(key interface{})
func (*RateLimitedExecutorPool) LoadOrStore ¶
func (c *RateLimitedExecutorPool) LoadOrStore(key interface{}) *RateLimitedExecutor
LoadOrStore returns the existing RateLimitedExecutor for the key if present. Otherwise, it will create new RateLimitedExecutor with a new underlying rate-limiter, store and return it.