climit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrencyLimit

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

ConcurrencyLimit enforce a concurrency limit with tokens that need to be held by routines. A Token can be acquired by calling Acquire(), and MUST be released by calling Token.Release().

func New

func New(dbname, name string, limit int, logger logrus.FieldLogger) *ConcurrencyLimit

New creates a new ConcurrencyLimit with a given limit. The name is used for Prometheus metrics.

func (*ConcurrencyLimit) Acquire

func (cl *ConcurrencyLimit) Acquire() *Token

Acquire acquires a Token. It will block until a free Token is available. You MUST call Token.Release() when you are done with the operation.

type Token

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

Token represents the token that allows the caller to proceed with a limited operation.

func (*Token) Release

func (t *Token) Release() time.Duration

Release releases the Token. It can safely be called more than once, even from different goroutines. It returns how long the Token was held, or 0 if it had already been released.

Jump to

Keyboard shortcuts

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