2016-04-05 22:04:37 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2018-03-03 14:53:52 +03:00
|
|
|
"context"
|
2016-04-05 22:04:37 +03:00
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|