try

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MIT Imports: 4 Imported by: 2

README

try

a function to repeat another one until it succeeds

Documentation

Index

Constants

View Source
const (
	DefaultDelay   = time.Second
	DefaultBackoff = DefaultDelay * 64
)

Variables

View Source
var (
	ErrAttempt  = errors.New("try: max attempt reached")
	ErrAbort    = errors.New("try: abort")
	ErrNoErr    = errors.New("try: no error")
	ErrDuration = errors.New("try: invalid duration")
)

Functions

func Forever added in v1.2.0

func Forever(try TryFunc) error

func Try

func Try(max int, try TryFunc) error

func TryContext added in v1.2.0

func TryContext(ctx context.Context, max int, try TryFunc) error

Types

type JitterFunc

type JitterFunc func() time.Duration

type Option

type Option func(r *Retry) error

func WithBackoff

func WithBackoff(d time.Duration) Option

func WithJitter

func WithJitter(fn JitterFunc) Option

func WithWait

func WithWait(d time.Duration) Option

type Retry

type Retry struct {
	// contains filtered or unexported fields
}

func New

func New(limit int, options ...Option) (*Retry, error)

func (*Retry) Try

func (r *Retry) Try(try TryFunc) error

func (*Retry) TryContext added in v1.2.0

func (r *Retry) TryContext(ctx context.Context, try TryFunc) error

type TryFunc

type TryFunc func(int) error

Jump to

Keyboard shortcuts

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