executor

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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.

func (*LimitedBackoff) Step

func (l *LimitedBackoff) Step()

Step calculates the next backoff.

type LimitedBackoffCreator

type LimitedBackoffCreator struct {
	// contains filtered or unexported fields
}

func NewExponentialLimitedBackoffCreator

func NewExponentialLimitedBackoffCreator() LimitedBackoffCreator

func (*LimitedBackoffCreator) New

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL