Skip to content

IsSkyfalls/go-retry-generics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-retry-generics

good names are all taken


Simple golang library for retry logic with fluent APIs.

slightly inspired by avast/retry-go

Example

Install/update with go get -u github.com/IsSkyfalls/go-retry-generics/retry

import "github.com/IsSkyfalls/go-retry-generics/retry"

//or this, so you can use the functions directly without any qualifier
import."github.com/IsSkyfalls/go-retry-generics/retry"
// since go doesn't have overloading, you'll need to specify the combination of the input and outputs
// 0-8 is supported. If you somehow need more, seek help immediately
i, err := retry.Try1to1(func(in int) (int, error) {
        // do something that might error out
        return in * 2, nil
    }).
    WithBackoff(
		retry.Fibonacci(). // use the fibonacci sequence as the delay function for retries
        WithJitter(500 * time.Millisecond), // with a +-500ms jitter
    ).
    ForTimes(10). // try for 10 times before giving up
    Run(2)        // run with input 2 
	
fmt.Println(err)
fmt.Println(i)

Usage

For the most part, autocomplete will guide you through the API without needing to consult any documentation or sourcecode.

Or I'm just lazy to finish this part.

BackoffTimingFunc

Check timing.go.

About

A golang library for retry logic with fluent APIs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages