backoff

package module
v0.0.0-...-73b5755 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2016 License: BSD-2-Clause-Views Imports: 4 Imported by: 0

README

Backoff

Simple implementation of an exponential backoff mechanism, including helpers for establishing network connections.

go get github.com/jamescun/backoff

GoDoc

Example

b := backoff.New(100 * time.Millisecond, 5)

err := b.Do(func() error {
	conn, err = net.Dial("tcp", "flapping-network-server.local:80")
	if err != nil {
		return err
	}

	return nil
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	// minimum backoff time
	Minimum time.Duration

	// maximum number of failures to tolerate
	Maximum int

	// add randomness to backoff duration
	// http://www.awsarchitectureblog.com/2015/03/backoff.html
	Jitter bool
}

func New

func New(min time.Duration, max int) Backoff

create a new exponential Backoff assignment with minimum time between failures and maximum total failures.

func (Backoff) Dial

func (b Backoff) Dial(network, address string) (conn net.Conn, err error)

implements dialer interface with exponential backoff mechanism.

func (Backoff) Do

func (b Backoff) Do(fn func() error) (err error)

execute function fn with exponential backoff mechanism. will return last error returned by fn, or nil on first successful attempt.

Jump to

Keyboard shortcuts

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