Name: backoff
Owner: Kik Interactive
Description: The exponential backoff algorithm in Go (Golang).
Created: 2015-08-11 14:48:07.0
Updated: 2017-05-21 17:21:43.0
Pushed: 2015-08-16 09:10:33.0
Homepage: https://godoc.org/github.com/cenkalti/backoff
Size: 108
Language: Go
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This is a Go port of the exponential backoff algorithm from google-http-java-client.
Exponential backoff is an algorithm that uses feedback to multiplicatively decrease the rate of some process, in order to gradually find an acceptable rate. The retries exponentially increase and stop increasing when a certain threshold is met.
et github.com/cenkalti/backoff
Simple retry helper that uses exponential back-off algorithm:
ation := func() error {
// An operation that might fail
:= backoff.Retry(operation, backoff.NewExponentialBackOff())
rr != nil {
// handle error
peration is successfull
Ticker example:
ation := func() error {
// An operation that may fail
backoff.NewExponentialBackOff()
er := backoff.NewTicker(b)
err error
icks will continue to arrive when the previous operation is still running,
o operations that take a while to fail could run in quick succession.
t = range ticker.C {
if err = operation(); err != nil {
log.Println(err, "will retry...")
continue
}
ticker.Stop()
break
rr != nil {
// Operation has failed.
peration is successfull.