abursavich / retry

Package retry provides backoff algorithms for retryable processes.

Home Page:https://bursavich.dev/retry

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

https://bursavich.dev/retry

License:MIT License


Languages

Language:Go 100.0%