2019-05-31 01:52:10 +03:00
|
|
|
// Package backoff provides backoff functionality
|
2021-10-02 19:55:07 +03:00
|
|
|
package backoff // import "go.unistack.org/micro/v3/util/backoff"
|
2019-05-31 01:52:10 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-02-02 23:32:55 +03:00
|
|
|
// Do is a function x^e multiplied by a factor of 0.1 second.
|
|
|
|
// Result is limited to 2 minute.
|
2019-05-31 01:52:10 +03:00
|
|
|
func Do(attempts int) time.Duration {
|
2020-02-02 23:32:55 +03:00
|
|
|
if attempts > 13 {
|
|
|
|
return 2 * time.Minute
|
2019-05-31 01:52:10 +03:00
|
|
|
}
|
2020-02-02 23:32:55 +03:00
|
|
|
return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100
|
2019-05-31 01:52:10 +03:00
|
|
|
}
|