ratelimiter

package
v0.0.0-...-cd31975 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdaptiveOption

type AdaptiveOption func(*adaptiveOptions)

AdaptiveOption configures an adaptive rate limiter.

func Window

func Window(w time.Duration) AdaptiveOption

Window configures how often statistics about capacity usage are collected. A shorter value gives you a quicker reaction time, but at the cost of increasing the risk of oscillations. The default value is 10 seconds.

type AdaptiveQPS

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

AdaptiveQPS is a rate limiter that will try to guess what is the optional capacity to request. It will try to fo as fast as possible, but it will release some capacity if the client cannot keep up with the capacity it received.

func (*AdaptiveQPS) Close

func (arl *AdaptiveQPS) Close()

Close closes the adjustible rate limiter. It should be called only once.

func (*AdaptiveQPS) Wait

func (arl *AdaptiveQPS) Wait(ctx context.Context) error

Wait records entry time and blocks until the goroutine is released.

type RateLimiter

type RateLimiter interface {
	// Wait blocks until the appropriate operation runs or an error occurs.
	Wait(ctx context.Context) error

	// Close closes the rate limiter.
	Close()
}

RateLimiter is a rate limiter that works with Doorman resources.

func NewAdaptiveQPS

func NewAdaptiveQPS(res doorman.Resource, options ...AdaptiveOption) RateLimiter

NewAdaptiveQPS creates a rate limiter connected to the resource.

func NewQPS

func NewQPS(res doorman.Resource) RateLimiter

NewQPS creates a rate limiter connected to the resourse.

Jump to

Keyboard shortcuts

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