backoff

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMinDuration = 5 * time.Second
	DefaultMaxDuration = 60 * time.Second
	DefaultFactor      = float64(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

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

func NewBackoff

func NewBackoff(cfg ...Config) *Backoff

func (*Backoff) Next

func (b *Backoff) Next(attempt int) time.Duration

type Config

type Config struct {
	Min    time.Duration
	Max    time.Duration
	Factor float64
}

type Ticker added in v0.6.0

type Ticker struct {
	// Public copy of channel which receives time ticks.
	C <-chan time.Time
	// contains filtered or unexported fields
}

Ticker extends logic of standard time.Ticker with backoff strategy. Each next time tick will increase by a specific backoff delay.

For implementation we using resource below. https://github.com/cenkalti/backoff/blob/v4.3.0/ticker.go.

func NewTicker added in v0.6.0

func NewTicker(backoff *Backoff, minDuration time.Duration, seed int) *Ticker

NewTicker creates new Ticker.

You can use it as time.Ticker. The structure provides a C channel for receiving time tick events.

Arguments:

backoff - structure for generating backoff duration.
minDuration - the min duration of the next tick. In most cases
this duration will be added to the generated backoff duration.
factor - a random number that will be used to generate a random
backoff duration. We will use numbers from 1 to 'factor' to generate
a random backoff based on math/random/v2 functions.

Example:

func main() {
  // Like default time.Ticker()
  ticker := backoff.NewTicker(...)

  <-ticker.C
}

func (*Ticker) Stop added in v0.6.0

func (t *Ticker) Stop()

Jump to

Keyboard shortcuts

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