retry

package
v0.0.0-...-305ec12 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2015 License: MIT, MIT Imports: 1 Imported by: 0

README

Go retry package with timeout and retry limits.

Usage

...

import "github.com/ae6rt/retry"

retry := retry.New(3*time.Second, 3, retry.DefaultBackoffFunc)
work := func() error {
   // do stuff
   return nil
}

err := retry.Try(work)
if err != nil {
   if retry.IsTimeout(err) {
     fmt.Printf("Timeout\n")
   } else {
     fmt.Printf("Error: %v\n", err)
   }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBackoffFunc = func(attempts uint) {
	if attempts == 0 {
		return
	}
	time.Sleep((1 << attempts) * time.Millisecond)
}

Functions

func IsTimeout

func IsTimeout(err error) bool

Types

type Retry

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

func New

func New(timeout time.Duration, maxAttempts uint, backoffFunc func(uint)) Retry

func (Retry) Try

func (r Retry) Try(work func() error) error

Jump to

Keyboard shortcuts

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