throttler

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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