micro/client/backoff.go

15 lines
416 B
Go
Raw Normal View History

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)
2020-01-30 19:43:03 +03:00
// exponential backoff is a function x^e multiplied by a factor of 0.1 second.
2016-04-05 22:04:37 +03:00
func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) {
return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100, nil
2016-04-05 22:04:37 +03:00
}