https://github.com/indrasaputra/backoff
Implementation of Backoff Strategy written in Go (Golang)
https://github.com/indrasaputra/backoff
backoff backoff-strategy go golang
Last synced: 8 months ago
JSON representation
Implementation of Backoff Strategy written in Go (Golang)
- Host: GitHub
- URL: https://github.com/indrasaputra/backoff
- Owner: indrasaputra
- License: mit
- Created: 2018-05-16T04:05:12.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2021-03-16T02:14:57.000Z (about 5 years ago)
- Last Synced: 2025-09-07T02:42:49.103Z (9 months ago)
- Topics: backoff, backoff-strategy, go, golang
- Language: Go
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/indrasaputra/backoff)
[](https://codecov.io/gh/indrasaputra/backoff)
[](https://codeclimate.com/github/indrasaputra/backoff/test_coverage)
[](https://codeclimate.com/github/indrasaputra/backoff/maintainability)
[](https://goreportcard.com/report/github.com/indrasaputra/backoff)
[](http://godoc.org/github.com/indrasaputra/backoff)
# Backoff
Backoff strategy written in Go
## Description
Backoff is an implementation of the popular backoff strategy. It is written in Go.
## Installation
```sh
go get github.com/indrasaputra/backoff
```
## Usage
There are two actual backoff implementations. The first one is `ConstantBackoff` and the second one is `ExponentialBackoff`.
```go
package main
import (
"time"
"github.com/indrasaputra/backoff"
)
func main() {
b := &backoff.ConstantBackoff{
BackoffInterval: 200 * time.Millisecond,
JitterInterval: 50 * time.Millisecond,
}
// use NextInterval() to get the next interval
interval := b.NextInterval()
// use Reset() to reset the backoff
b.Reset()
}
```
If you want to use `ExponentialBackoff`, simply follow this code
```go
package main
import (
"time"
"github.com/indrasaputra/backoff"
)
func main() {
b := backoff.ExponentialBackoff{
BackoffInterval: 300 * time.Millisecond,
JitterInterval: 100 * time.Millisecond,
MaxInterval: 3 * time.Second,
Multiplier: 2,
}
}
```