Skip to content

Package retry provides backoff algorithms for retryable processes.

License

Notifications You must be signed in to change notification settings

abursavich/retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Package retry provides backoff algorithms for retryable processes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages