https://github.com/abursavich/retry
Package retry provides backoff algorithms for retryable processes.
https://github.com/abursavich/retry
backoff exponential-backoff golang retry
Last synced: 3 months ago
JSON representation
Package retry provides backoff algorithms for retryable processes.
- Host: GitHub
- URL: https://github.com/abursavich/retry
- Owner: abursavich
- License: mit
- Created: 2022-08-24T01:46:23.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-11T18:39:09.000Z (almost 2 years ago)
- Last Synced: 2025-06-04T17:11:39.207Z (about 1 year ago)
- Topics: backoff, exponential-backoff, golang, retry
- Language: Go
- Homepage: https://bursavich.dev/retry
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Retry
[![License][license-img]][license]
[![GoDev Reference][godev-img]][godev]
[![Go Report Card][goreportcard-img]][goreportcard]
Package retry provides backoff algorithms for retryable processes.
It was inspired by [github.com/cenkalti/backoff/v4][backoff] 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.
```go
type Policy interface {
Next(err error, start, now time.Time, attempt int) (backoff time.Duration, retry bool)
}
```
It decomposes features and encourages their composition.
```go
policy := retry.WithRandomJitter(retry.ConstantBackoff(time.Second), 0.5)
```
It makes [context] first-class and improves call ergonomics.
```go
err := retry.Do(ctx, policy, func() error {
// ...
})
```
[license]: https://raw.githubusercontent.com/abursavich/retry/main/LICENSE
[license-img]: https://img.shields.io/badge/license-mit-blue.svg?style=for-the-badge
[godev]: https://pkg.go.dev/bursavich.dev/retry
[godev-img]: https://img.shields.io/static/v1?logo=go&logoColor=white&color=00ADD8&label=dev&message=reference&style=for-the-badge
[goreportcard]: https://goreportcard.com/report/bursavich.dev/retry
[goreportcard-img]: https://goreportcard.com/badge/bursavich.dev/retry?style=for-the-badge
[backoff]: https://pkg.go.dev/github.com/cenkalti/backoff/v4
[Google's HTTP Client Library for Java]: https://github.com/google/google-http-java-client/blob/da1aa993e90285ec18579f1553339b00e19b3ab5/google-http-client/src/main/java/com/google/api/client/util/ExponentialBackOff.java
[context]: https://pkg.go.dev/context#Context