micro/util/backoff/backoff.go
Vasiliy Tolstov 5eb0e56373 move all imports to own domain
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-10-02 19:55:07 +03:00

17 lines
413 B
Go

// Package backoff provides backoff functionality
package backoff // import "go.unistack.org/micro/v3/util/backoff"
import (
"math"
"time"
)
// Do is a function x^e multiplied by a factor of 0.1 second.
// Result is limited to 2 minute.
func Do(attempts int) time.Duration {
if attempts > 13 {
return 2 * time.Minute
}
return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100
}