poll

package
v0.10.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBaseDelay = errors.New("BaseDelay must be greater than 0")
	ErrInvalidTimeout   = errors.New("timeout must be greater than 0")
	ErrMaxSteps         = errors.New("max poll retry steps exceeded")
)

Functions

func BackoffWithContext

func BackoffWithContext(ctx context.Context, cfg Config, opFn func(context.Context) (bool, error)) error

BackoffWithContext repeatedly calls the operation until timeout is reached, it returns true, an error, or the context is canceled. It waits between attempts using exponential backoff, starting from Config.BaseDelay and increasing by Config.Factor, capped by Config.MaxDelay if set.

func CalculateBackoffDelay

func CalculateBackoffDelay(cfg *Config, tries int) time.Duration

CalculateBackoffDelay calculates the backoff delay for a given number of tries using exponential backoff with the provided configuration.

Types

type Config

type Config struct {
	// Initial delay before first retry
	BaseDelay time.Duration
	// Multiplier for delay on each retry
	Factor float64
	// Optional maximum delay between retries
	MaxDelay time.Duration
	// MaxSteps limits the number of retries. If 0, retries will continue until timeout.
	MaxSteps int
	// JitterFactor adds randomization to prevent thundering herd (0.0 to 1.0)
	JitterFactor float64
	// Rand is the random number generator for jitter calculation
	Rand *rand.Rand
}

Config defines parameters for exponential backoff polling.

func NewConfig added in v0.10.0

func NewConfig(baseDelay time.Duration, factor float64) *Config

NewConfig creates a new Config with a properly seeded random number generator.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration parameters are valid

Jump to

Keyboard shortcuts

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