Documentation
¶
Overview ¶
Package retry provides the most advanced interruptible mechanism to perform actions repetitively until successful.
Example ¶
package main import ( "context" "fmt" "log" "math/rand" "net" "time" "github.com/kamilsk/retry/v5" "github.com/kamilsk/retry/v5/backoff" "github.com/kamilsk/retry/v5/jitter" "github.com/kamilsk/retry/v5/strategy" ) var generator = rand.New(rand.NewSource(0)) func main() { what := SendRequest how := retry.How{ strategy.Limit(5), strategy.BackoffWithJitter( backoff.Fibonacci(10*time.Millisecond), jitter.NormalDistribution( rand.New(rand.NewSource(time.Now().UnixNano())), 0.25, ), ), strategy.CheckNetworkError(strategy.Skip), } breaker, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() if err := retry.Do(breaker, what, how...); err != nil { log.Fatal(err) } fmt.Println("success communication") } func SendRequest() error { if generator.Intn(5) > 3 { return &net.DNSError{Name: "unknown host", IsTemporary: true} } return nil }
Output: success communication
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do( breaker strategy.Breaker, action func() error, strategies ...func(strategy.Breaker, uint, error) bool, ) error
Do takes an action and performs it, repetitively, until successful.
Optionally, strategies may be passed that assess whether or not an attempt should be made.
func DoAsync ¶
func DoAsync( breaker strategy.Breaker, action func() error, strategies ...func(strategy.Breaker, uint, error) bool, ) error
DoAsync takes an action and performs it, repetitively, until successful.
Optionally, strategies may be passed that assess whether or not an attempt should be made.
Types ¶
Directories
¶
Path | Synopsis |
---|---|
Package backoff provides stateless methods of calculating durations based on a number of attempts made.
|
Package backoff provides stateless methods of calculating durations based on a number of attempts made. |
Package jitter provides methods of transforming durations.
|
Package jitter provides methods of transforming durations. |
Package strategy provides a way to define how retry is performed.
|
Package strategy provides a way to define how retry is performed. |
Click to show internal directories.
Click to hide internal directories.