go-retry-generics

command module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 2 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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