ratelimit

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimit provides a shared rate limiter for broker API clients.

It wraps golang.org/x/time/rate to provide context-aware, per-broker request throttling. Multiple callers sharing the same Limiter are serialized correctly without exceeding the configured rate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter throttles API requests using a token-bucket algorithm.

func New

func New(name string, rps float64, burst int) *Limiter

New creates a Limiter that allows rps requests per second with the given burst size. Burst controls how many requests can fire at once before throttling kicks in.

func (*Limiter) Allow

func (l *Limiter) Allow() bool

Allow reports whether a request can proceed right now without waiting.

func (*Limiter) Name

func (l *Limiter) Name() string

Name returns the limiter's name (for logging/debugging).

func (*Limiter) Wait

func (l *Limiter) Wait(ctx context.Context) error

Wait blocks until the limiter allows one request, or ctx is cancelled.

Jump to

Keyboard shortcuts

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