Skip to content

Latest commit

 

History

History
49 lines (34 loc) · 1.73 KB

README.md

File metadata and controls

49 lines (34 loc) · 1.73 KB

Retry

License GoDev Reference Go Report Card

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.

Why?

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 {
    // ...
})