ratelimiter

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: MIT Imports: 2 Imported by: 1

README

ratelimiter

release status GoDoc

This package provides a basic rate limiter using a token bucket.

Authors

  • Christophe Lambin

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

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

RateLimiter is a token bucket rate limiter.

func New

func New(ctx context.Context, interval time.Duration, capacity int) *RateLimiter

New returns a new RateLimiter. Tokens are refilled at the given interval, up to the given capacity until the context is canceled.

func (*RateLimiter) Acquire

func (rl *RateLimiter) Acquire(ctx context.Context) error

Acquire blocks until a token is available, or the context is canceled.

func (*RateLimiter) Release

func (rl *RateLimiter) Release()

Release returns a token to the bucket.

func (*RateLimiter) TokenCount

func (rl *RateLimiter) TokenCount() int

TokenCount returns the number of tokens in the bucket.

func (*RateLimiter) TryAcquire

func (rl *RateLimiter) TryAcquire() bool

TryAcquire returns true if a token is acquired, false otherwise.

Jump to

Keyboard shortcuts

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