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 ¶
- func Retry(ctx context.Context, fn func() error, Options ...func(o *Option)) error
- func WithAttempts(attempts int) func(o *Option)
- func WithBackoffDuration(backoffDuration time.Duration) func(o *Option)
- func WithOnRetry(fn func(attempt int, err error)) func(o *Option)
- func WithRetryIf(fn func(error) bool) func(o *Option)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAttempts ¶
func WithBackoffDuration ¶
func WithOnRetry ¶
WithOnRetry sets a callback invoked before each retry sleep. Useful for logging the retry attempt and error.
func WithRetryIf ¶
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.