throttler

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 4 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

Index

Constants

This section is empty.

Variables

View Source
var ErrResourceBusy = errors.New("resource busy, try again")

Functions

This section is empty.

Types

type Option

type Option func(*options)

func WithMaxQueueLen

func WithMaxQueueLen(maxQueueLen uint64) Option

WithMaxQueueLen sets the maximum length the queue can grow to.

type Throttler

type Throttler[T any] struct {
	// contains filtered or unexported fields
}

Throttler limits how many times an action is done concurrently and how many requests for these actions can be queued at max.

func NewThrottler

func NewThrottler[T any](maxConcurrentReqs uint, resource *T, opts ...Option) *Throttler[T]

NewThrottler returns a new throttler that will allow up to `maxConcurrentReqs` concurrent requests for resource `T`. See throttler.Option for other options.

func (*Throttler[T]) Do

func (t *Throttler[T]) Do(ctx context.Context, doer func(resource *T) error) error

Do lets caller acquire the resource within the context of a callback

func (*Throttler[T]) JobsRunning

func (t *Throttler[T]) JobsRunning() int

JobsRunning returns the number of Do calls that are running at the moment

func (*Throttler[T]) QueueLen

func (t *Throttler[T]) QueueLen() int

QueueLen returns the number of Do calls that is blocked on the resource

Jump to

Keyboard shortcuts

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