retry

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package retry provides a generic async function executor with retries for robustness against network failures. Functions are linked to a deadline, executed asynchronously and network or context errors retried with backoff until the deadline has elapsed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Retryer

type Retryer[T any] struct {
	// contains filtered or unexported fields
}

Retryer provides execution of functions asynchronously with retry adding robustness to network errors. The generic type T abstracts the deadline argument.

func New

func New[T any](timeoutFunc func(T) time.Time) (*Retryer[T], error)

New returns a new Retryer instance.

func NewForT

func NewForT[T any](
	_ *testing.T,
	ctxTimeoutFunc func(context.Context, T) (context.Context, context.CancelFunc),
	backoffProvider func() func() <-chan time.Time,
) (*Retryer[T], error)

NewForT returns a new Retryer instance for testing supporting a custom clock.

func (*Retryer[T]) DoAsync

func (r *Retryer[T]) DoAsync(parent context.Context, t T, name string, fn func(context.Context) error)

DoAsync will execute the function including retries on network or context errors. It is intended to be used asynchronously:

go retryer.DoAsync(ctx, duty, "foo", fn)

func (*Retryer[T]) Shutdown

func (r *Retryer[T]) Shutdown(ctx context.Context)

Shutdown triggers graceful shutdown and waits for all active function to complete or timeout.

Jump to

Keyboard shortcuts

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