concurrency

package
v0.0.0-...-4be1d82 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoLimit      uint  = 0
	AlwaysRecord int32 = 0
)

Variables

This section is empty.

Functions

func EstimatedWaitTime

func EstimatedWaitTime(limiter Limiter, average time.Duration) time.Duration

func NewMockLimiter

func NewMockLimiter(stubRun bool) *mockLimiter

func NewMockThrottler

func NewMockThrottler(run bool) *mockThrottler

func ThrottlerMiddleware

func ThrottlerMiddleware(th Throttler) func(next http.Handler) http.Handler

Types

type ErrThrottled

type ErrThrottled struct {
	WaitTime time.Duration
}

func (*ErrThrottled) Error

func (t *ErrThrottled) Error() string

type Limiter

type Limiter interface {
	// Run executes a function, making sure at most a certain number of calls are executing simultaneously
	// It does _not_ start a goroutine, the function will be executing on the caller's stack.
	// If the context is canceled while waiting, it will abort.
	Run(ctx context.Context, fn func() error) error

	// Waiting returns a (racy) counter of how many Run calls are currently waiting to run.
	Waiting() int32

	// Running returns a (racy) counter of how many Run calls are currently executing their function.
	Running() int32

	MaxConcurrency() uint
}

func NewGauge

func NewGauge(gauge gaugor, tags statsd.Tags) Limiter

func NewLimiter

func NewLimiter(concurrency uint) Limiter

func NewLimiterWithGauge

func NewLimiterWithGauge(concurrency uint, gauge gaugor, tags statsd.Tags) Limiter

func NewLimiterWithSampledGauge

func NewLimiterWithSampledGauge(concurrency uint, gauge gaugor, sampling int32, tags statsd.Tags) Limiter

NewLimiterWithSampledGauge creates a Limiter that will publish the a gauge every <sampling> Run

func NewSampledGauge

func NewSampledGauge(gauge gaugor, sampling int32, tags statsd.Tags) Limiter

type Throttler

type Throttler interface {
	Run(ctx context.Context, fn func() error) error
}

func NewThrottler

func NewThrottler(limiter Limiter, tracker timetracker.Tracker, waitTimeout time.Duration) Throttler

Jump to

Keyboard shortcuts

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