First crack at backoff function

This commit is contained in:
Asim
2016-04-05 20:04:37 +01:00
parent 56c6993eb8
commit 7167f998ce
5 changed files with 86 additions and 0 deletions

18
client/backoff.go Normal file
View File

@@ -0,0 +1,18 @@
package client
import (
"math"
"time"
"golang.org/x/net/context"
)
type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error)
// exponential backoff
func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) {
if attempts == 0 {
return time.Duration(0), nil
}
return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond, nil
}