limiting

package
v0.0.0-...-3e7ca94 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyLimit

type KeyLimit struct {
	Keys  []string
	Limit int64
}

KeyLimit defines a concurrency limit for a set of keys.

All keys of one set share the same limit. Keys of different sets have separate limits.

Sets must not overlap.

type Limiter

type Limiter interface {
	// Acquire attempts to reserve a slot without blocking.
	//
	// Returns a release function and true if successful. The function must be
	// called to release the limiter. The function must be called exactly once.
	// Calling the function more that once will cause incorrect behavior of the
	// limiter.
	//
	// Returns nil and false if fails.
	//
	// If the key was not defined in the limiter, no limit is applied.
	Acquire(key string) (ReleaseFunc, bool)
}

type ReleaseFunc

type ReleaseFunc func()

type SemaphoreLimiter

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

func NewSemaphoreLimiter

func NewSemaphoreLimiter(limits []KeyLimit) (*SemaphoreLimiter, error)

func (*SemaphoreLimiter) Acquire

func (lr *SemaphoreLimiter) Acquire(key string) (ReleaseFunc, bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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