limiter

package
v0.0.0-...-20e21a9 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParams = xerrors.New("parameter invalid")
)

Errors

Functions

This section is empty.

Types

type Controller

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

Controller is a struct to create and control Limiters.

func NewController

func NewController(interval time.Duration, ticks uint, commonCPS int64, perChildCPS int64) *Controller

NewController creates a new controller instance. interval is a period of time measuring is performed. ticks is a number of gaps interval is divided to. commonCPS is a spped liimit common for all the derrived Limiters. perChildCPS is a default value for each derrived Limiter. Note: each Limiter have 3 limits: it's own one, perChildCPS, and commonCPS. Minimal one is applied in any case. commonCPS is a limit for all the derrived Limiters together.

func (*Controller) BornLimiter

func (c *Controller) BornLimiter() *Limiter

BornLimiter returns a new limiter

func (*Controller) SetCommonCPS

func (c *Controller) SetCommonCPS(cps int64)

SetCommonCPS sets the one for all together limit

func (*Controller) SetPerChildCPS

func (c *Controller) SetPerChildCPS(cps int64)

SetPerChildCPS changes a default limit for the new Limiters and also reset the limit on al the existing Limiters.

type Limiter

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

Limiter is an actual limiting unit

func (*Limiter) FillUp

func (l *Limiter) FillUp(n int64) int64

FillUp is used to report counter to Limiter.

func (*Limiter) SetCPS

func (l *Limiter) SetCPS(cps int64)

SetCPS sets the limit.

Jump to

Keyboard shortcuts

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