Package retry provides backoff algorithms for retryable processes.
It was inspired by github.com/cenkalti/backoff/v4 which is a port of Google's HTTP Client Library for Java.
It separates state from policy, which reduces allocations and allows a single policy instance to be used concurrently by all callers, and it uses explicit return values instead of magic sentinel values.
type Policy interface {
Next(err error, start, now time.Time, attempt int) (backoff time.Duration, retry bool)
}
It decomposes features and encourages their composition.
policy := retry.WithRandomJitter(retry.ConstantBackoff(time.Second), 0.5)
It makes context first-class and improves call ergonomics.
err := retry.Do(ctx, policy, func() error {
// ...
})