Skip to content

Utilities to retry fallible function calls with exponential backoff

Notifications You must be signed in to change notification settings

IQ-tech/go-retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retry a function with exponential backoff

This project provide utilities to retry fallible function calls

Installation

To install, use go get

go get github.com/IQ-tech/go-retry

Usage

Retrying a function call

// We will attempt the function call 3 times
// with an initial waiting time of 3 seconds.
retryOptions := retry.Options{
	Attempts:                  3,
	InitialTimeBetweenRetries: 3,
}

value, err = retry.Func(retryOptions, func() (interface{}, error) {
	return someservice.GetSomeValue()
})

// [err] will be non nil if the function didn't succeed after
// the maximum number of attempts has been reached.
if err != nil {
  panic(err)
}

fmt.Println(value)

About

Utilities to retry fallible function calls with exponential backoff

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages