retrier

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package retrier provides configurable retry logic with backoff for operations that may transiently fail (e.g. network calls, MCP connections).

It solves the problem of centralizing retry behavior: callers pass a function and options (attempts, backoff duration, retry-if predicate, on-retry hook). Do runs the function and retries on error according to the options. Without this package, each integration would implement its own retry loops and backoff logic inconsistently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(ctx context.Context, fn func() error, Options ...func(o *Option)) error

func WithAttempts

func WithAttempts(attempts int) func(o *Option)

func WithBackoffDuration

func WithBackoffDuration(backoffDuration time.Duration) func(o *Option)

func WithOnRetry

func WithOnRetry(fn func(attempt int, err error)) func(o *Option)

WithOnRetry sets a callback invoked before each retry sleep. Useful for logging the retry attempt and error.

func WithRetryIf

func WithRetryIf(fn func(error) bool) func(o *Option)

WithRetryIf sets a predicate that determines whether an error is retryable. If the predicate returns false, the error is returned immediately without further retries. By default all errors are retried.

Types

type Option

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

Jump to

Keyboard shortcuts

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