backoff

package module
v0.0.0-...-1699467 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2016 License: Apache-2.0 Imports: 2 Imported by: 0

README

Backoff library with maximum number of calls

Usage:

Please do copy & paste the code, don't create more dependencies :)

// Retries the function f backing off the double of
// time each retry until a successfully call is made.
retry := backoff.NewDoubleTimeBackoff(100*time.Millisecond, 1*time.Second, 10)

// it would retry after 100 Millis, 200 Millis, 400 Millis, ..., up to 1 Second, 10 times in total
retry.Do(func() error {
  return MyLogic()
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoubleTimeBackoff

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

func (*DoubleTimeBackoff) Do

func (b *DoubleTimeBackoff) Do(f func() error) error

type NilBackoff

type NilBackoff struct{}

func (NilBackoff) Do

func (NilBackoff) Do(f func() error) error

type Retrier

type Retrier interface {
	// Do executes the function doing retries in case it returns an error
	Do(f func() error) error
}

func NewDoubleTimeBackoff

func NewDoubleTimeBackoff(initialBackoff, maxBackoff time.Duration, maxCalls int) Retrier

NewDoubleTimeBackoff retries the function f backing off the double of time each retry until a successfully call is made. initialBackoff is minimal time to wait for the next call maxBackoff is the maximum time between calls, if is 0 there is no maximum maxCalls is the maximum number of calls to the function, if is 0 there is no maximum

func NewNilBackoff

func NewNilBackoff() Retrier

NewNilBackoff it just calls the function, it usefull for testing

Jump to

Keyboard shortcuts

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