ratelimit

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ratelimit rate-caps admissions per key, the shape the node's doors share: one admission per interval for each key, in bounded memory. A shared library: no loops of its own, no policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keyed

type Keyed[K comparable] struct {
	// contains filtered or unexported fields
}

Keyed rate-caps admissions per key: one admission per interval, and a key silent for an interval is admitted again and stops being tracked. It tracks at most keyCap keys and sweeps the silent ones at most once per interval, so a flood of fresh keys costs bounded memory and amortized time; a fresh key arriving while the table is full is refused.

func NewKeyed

func NewKeyed[K comparable](interval time.Duration) *Keyed[K]

NewKeyed returns a limiter that admits each key at most once per interval.

func (*Keyed[K]) Admit

func (l *Keyed[K]) Admit(key K) bool

Admit reports whether the key may be admitted now, recording the admission when it may.

Jump to

Keyboard shortcuts

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