throttle

package
v0.60.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package throttle keeps the registry clients away from an upstream that asked to wait with a Retry-After header (RFC 9110, section 10.2.3), so a check fails fast instead of calling it again too soon.

Index

Constants

View Source
const MaxWait = time.Hour

MaxWait caps a Retry-After, a choice: an absurd one must not keep an upstream unused until the next restart.

Variables

This section is empty.

Functions

This section is empty.

Types

type Throttle

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

Throttle remembers, per host, until when an upstream asked not to be called. It is safe for concurrent use.

func New

func New(now func() time.Time) *Throttle

New returns a Throttle that dates the waits with now.

func (*Throttle) Allows

func (t *Throttle) Allows(host string) bool

Allows reports whether host may be called now, and forgets a wait that is over.

func (*Throttle) Heed

func (t *Throttle) Heed(host string, err error)

Heed waits as long as err asks: an *httpclient.StatusError that carries a Retry-After. Any other error is ignored.

func (*Throttle) Wait

func (t *Throttle) Wait(host string, d time.Duration)

Wait keeps host from being called for d, at most MaxWait.

Jump to

Keyboard shortcuts

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