limiter

package
v3.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentLimiter

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

ConcurrentLimiter plugin for hprose.

func NewConcurrentLimiter

func NewConcurrentLimiter(maxConcurrentRequests int, timeout ...time.Duration) *ConcurrentLimiter

NewConcurrentLimiter returns a ConcurrentLimiter instance.

func (*ConcurrentLimiter) Acquire

func (l *ConcurrentLimiter) Acquire(ctx context.Context) (err error)

Acquire returns immediately when the concurrentRequests is less than or equal to maxConcurrentRequests, otherwise it will block until timeout or any request are completed.

func (*ConcurrentLimiter) ConcurrentRequests

func (l *ConcurrentLimiter) ConcurrentRequests() int

ConcurrentRequests property of ConcurrentLimiter.

func (*ConcurrentLimiter) Handler

func (l *ConcurrentLimiter) Handler(ctx context.Context, request []byte, next core.NextIOHandler) (response []byte, err error)

Handler for ConcurrentLimiter.

func (*ConcurrentLimiter) MaxConcurrentRequests

func (l *ConcurrentLimiter) MaxConcurrentRequests() int

MaxConcurrentRequests property of ConcurrentLimiter.

func (*ConcurrentLimiter) Release

func (l *ConcurrentLimiter) Release()

Release reqeust task queue.

func (*ConcurrentLimiter) Timeout

func (l *ConcurrentLimiter) Timeout() time.Duration

Timeout property of ConcurrentLimiter.

type Option

type Option func(*RateLimiter)

Option for RateLimiter.

func WithMaxPermits

func WithMaxPermits(maxPermits float64) Option

WithMaxPermits returns a maxPermits Option for RateLimiter.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout returns a timeout Option for RateLimiter.

type RateLimiter

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

RateLimiter plugin for hprose.

func NewRateLimiter

func NewRateLimiter(permitsPerSecond int64, options ...Option) *RateLimiter

NewRateLimiter returns a RateLimiter instance.

func (*RateLimiter) Acquire

func (l *RateLimiter) Acquire(ctx context.Context, tokens int) (err error)

Acquire is the core algorithm of RateLimiter.

func (*RateLimiter) IOHandler

func (l *RateLimiter) IOHandler(ctx context.Context, request []byte, next core.NextIOHandler) (response []byte, err error)

IOHandler for RateLimiter.

func (*RateLimiter) InvokeHandler

func (l *RateLimiter) InvokeHandler(ctx context.Context, name string, args []interface{}, next core.NextInvokeHandler) (result []interface{}, err error)

InvokeHandler for RateLimiter.

func (*RateLimiter) MaxPermits

func (l *RateLimiter) MaxPermits() float64

MaxPermits property of RateLimiter.

func (*RateLimiter) PermitsPerSecond

func (l *RateLimiter) PermitsPerSecond() int64

PermitsPerSecond property of RateLimiter.

func (*RateLimiter) Timeout

func (l *RateLimiter) Timeout() time.Duration

Timeout property of RateLimiter.

Jump to

Keyboard shortcuts

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