backoff

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Overview

Package backoff implements backoff timers which increases wait time on every retry, incredibly useful in distributed system timeout functionalities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

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

Backoff implements exponential backoff with randomized wait times.

func New

func New(ctx context.Context, cfg Config) *Backoff

New creates a Backoff object. Pass a Context that can also terminate the operation.

func (*Backoff) Err

func (b *Backoff) Err() error

Err returns the reason for terminating the backoff, or nil if it didn't terminate.

func (*Backoff) NextDelay

func (b *Backoff) NextDelay() time.Duration

func (*Backoff) NumRetries

func (b *Backoff) NumRetries() int

NumRetries returns the number of retries so far.

func (*Backoff) Ongoing

func (b *Backoff) Ongoing() bool

Ongoing returns true if caller should keep going.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset the Backoff back to its initial condition.

func (*Backoff) Wait

func (b *Backoff) Wait()

Wait sleeps for the backoff time then increases the retry count and backoff time. Returns immediately if Context is terminated.

type Config

type Config struct {
	Min        time.Duration `yaml:"min_period"`  // Start backoff at this level
	Max        time.Duration `yaml:"max_period"`  // Increase exponentially to this level
	MaxRetries int           `yaml:"max_retries"` // Give up after this many; zero means infinite retries
}

Config configures a Backoff.

Jump to

Keyboard shortcuts

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