micro/util/backoff/backoff.go

17 lines
363 B
Go
Raw Normal View History

2019-05-30 23:52:10 +01:00
// Package backoff provides backoff functionality
package backoff
2019-05-30 23:52:10 +01:00
import (
"math"
"time"
)
// Do is a function x^e multiplied by a factor of 0.1 second.
// Result is limited to 2 minute.
2019-05-30 23:52:10 +01:00
func Do(attempts int) time.Duration {
if attempts > 13 {
return 2 * time.Minute
2019-05-30 23:52:10 +01:00
}
return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100
2019-05-30 23:52:10 +01:00
}