try – github.com/matryer/try Index | Files

package try

import "github.com/matryer/try"

Package try provides retry functionality.

var value string
err := try.Do(func(attempt int) (bool, error) {
  var err error
  value, err = SomeFunction()
  return attempt < 5, err // try 5 times
})
if err != nil {
  log.Fatalln("error:", err)
}

Index

Variables

var MaxRetries = 10

MaxRetries is the maximum number of retries before bailing.

Functions

func Do

func Do(fn Func) error

Do keeps trying the function until the second argument returns false, or no error is returned.

func IsMaxRetries

func IsMaxRetries(err error) bool

IsMaxRetries checks whether the error is due to hitting the maximum number of retries or not.

Types

type Func

type Func func(attempt int) (retry bool, err error)

Func represents functions that can be retried.

Source Files

doc.go try.go

Version
v0.0.0-20161228173917-9ac251b645a2 (latest)
Published
Dec 28, 2016
Platform
windows/amd64
Imports
1 packages
Last checked
now

Tools for package owners.