Documentation
¶
Overview ¶
Package retry implements a retry mechanism with backoff.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run executes the function while the Policy allows. until it returns nil or Stop.
Example ¶
package main
import (
"time"
"github.com/hamba/pkg/retry"
)
func main() {
pol := retry.ExponentialPolicy(3, time.Millisecond)
err := retry.Run(pol, func() error {
// Do work
return nil
})
if err != nil {
// Handle the error
}
}
func Stop ¶
Stop wraps an error and stops retrying.
Example ¶
package main
import (
"errors"
"time"
"github.com/hamba/pkg/retry"
)
func main() {
pol := retry.ExponentialPolicy(3, time.Millisecond)
err := retry.Run(pol, func() error {
// Do work that results in error
return retry.Stop(errors.New("test error"))
})
if err != nil {
// Handle the error
}
}
Types ¶
Click to show internal directories.
Click to hide internal directories.