ratelimit

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter interface {
	// Consume is a blocking call once you have
	Consume(context.Context) error
}

Limiter defines the basic definition of a rater limiter

type NullLimiter

type NullLimiter struct{}

NullLimiter satisfies the Limiter interface and should only be used for testing purposes

func (*NullLimiter) Consume

func (*NullLimiter) Consume(_ context.Context) error

Consume will allow anything and always return nil

type Throttler

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

Throttler allows for up to fix number of actions to happen within a fixed interval with accounting for jitters

func NewThrottler

func NewThrottler(limit int64, interval, jitter time.Duration) *Throttler

NewThrottler will configure a new rater limiting bucket with max of limit / (interval + [0,jitter)) ==> rate Once the limit has been breached, it will pause computation for that thread until the interval + jitter amount has been reached

func (*Throttler) Consume

func (lb *Throttler) Consume(ctx context.Context) error

Consume will take one place in the internal semiphore and will block once we have reached out limit and delay the processing of blocked this does mean that blocked will be delayed instead of dropped.

func (*Throttler) Start

func (lb *Throttler) Start()

Start runs a background go routine that was reset the sync limit based on the interval and jitter time

func (*Throttler) Stop

func (lb *Throttler) Stop()

Stop will stop the background task to reset the bucket from running and will release anyone waiting for the

Jump to

Keyboard shortcuts

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