throttler

package
v0.29.6 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketThrottler

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

BucketThrottler is implementation of token-bucket algorithm for rate-limiting

func NewBucketThrottler

func NewBucketThrottler(limit int) *BucketThrottler

NewBucketThrottler create a new instance of BucketThrottler which limit

func NewBucketThrottlerBacklog

func NewBucketThrottlerBacklog(limit int, backlog int, timeout time.Duration) *BucketThrottler

NewBucketThrottlerBacklog crete a new instance of Throttler which more configuration options

func (*BucketThrottler) Release

func (t *BucketThrottler) Release()

Release return toke to bucket

func (*BucketThrottler) Take

func (t *BucketThrottler) Take(ctx context.Context) bool

Take retrieve a token from bucket

type NopThrottler

type NopThrottler struct {
}

NopThrottler is always return that you can perform given operation

func NewNopThrottler

func NewNopThrottler(_ ...interface{}) *NopThrottler

NewNopThrottler create instance of NopThrottler

func (*NopThrottler) Release

func (*NopThrottler) Release()

Release do nothing

func (*NopThrottler) Take

func (*NopThrottler) Take(_ context.Context) bool

Take return always true

type Throttler

type Throttler interface {
	Take(ctx context.Context) (taken bool) // Take tries acquire token when its true its mean you can process when false have been throttled
	Release()                              // Release returns token to pool
}

Throttler is rate limiter

Jump to

Keyboard shortcuts

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