ratelimit

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	// configuration options
	RateLimitPerSecond     int
	InitializeWithoutSlack bool
	// contains filtered or unexported fields
}

RateLimiter struct wraps ratelimit package

RateLimitPerson = 0 = unlimited = no rate limit

func (*RateLimiter) Init

func (r *RateLimiter) Init()

Init will setup the rate limit for use

func (*RateLimiter) Take

func (r *RateLimiter) Take() time.Time

Take is called by each method needing rate limit applied, based on the rate limit per second setting, given amount of time is slept before process continues, for example, 1 second rate limit 100 = 10 milliseconds per call, this causes each call to Take() sleep for 10 milliseconds, if rate limit is unlimited, then no sleep delay will occur (thus no rate limit applied)

in other words, each call to take blocks for certain amount of time per rate limit per second configured, call to Take() returns time.Time for the Take() that took place

Jump to

Keyboard shortcuts

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