limiter

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("timeout exceeded")

Functions

This section is empty.

Types

type NoopLimiter added in v0.12.1

type NoopLimiter struct {
}

ServerLimiter provides interface to limit amount of requests

func (NoopLimiter) Capacity added in v0.12.1

func (l NoopLimiter) Capacity() int

func (NoopLimiter) Enter added in v0.12.1

func (l NoopLimiter) Enter(ctx context.Context, s string) error

Enter claims one of free slots or blocks until there is one.

func (NoopLimiter) Leave added in v0.12.1

func (l NoopLimiter) Leave(ctx context.Context, s string)

Frees a slot in limiter

type RealLimiter added in v0.12.1

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

ServerLimiter provides interface to limit amount of requests

func (RealLimiter) Capacity added in v0.12.1

func (sl RealLimiter) Capacity() int

func (RealLimiter) Enter added in v0.12.1

func (sl RealLimiter) Enter(ctx context.Context, s string) error

Enter claims one of free slots or blocks until there is one.

func (RealLimiter) Leave added in v0.12.1

func (sl RealLimiter) Leave(ctx context.Context, s string)

Frees a slot in limiter

type ServerLimiter

type ServerLimiter interface {
	Capacity() int
	Enter(ctx context.Context, s string) error
	Leave(ctx context.Context, s string)
}

func NewServerLimiter

func NewServerLimiter(servers []string, l int) ServerLimiter

NewServerLimiter creates a limiter for specific servers list.

type SimpleLimiter added in v0.12.0

type SimpleLimiter chan struct{}

func NewSimpleLimiter added in v0.12.0

func NewSimpleLimiter(l int) SimpleLimiter

func (SimpleLimiter) Enter added in v0.12.0

func (l SimpleLimiter) Enter()

func (SimpleLimiter) Leave added in v0.12.0

func (l SimpleLimiter) Leave()

Jump to

Keyboard shortcuts

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