mirror of
https://github.com/Luzifer/rootzone.git
synced 2024-12-20 11:21:19 +00:00
26 lines
342 B
Go
26 lines
342 B
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
maxRetries = 5
|
|
retryDelay = 1.2
|
|
)
|
|
|
|
func retry(f func() error) error {
|
|
var err error
|
|
|
|
for i := 1; i <= maxRetries; i++ {
|
|
if err = f(); err == nil {
|
|
return nil
|
|
}
|
|
|
|
sleep := time.Duration(math.Pow(retryDelay, float64(i)) * float64(time.Second))
|
|
time.Sleep(sleep)
|
|
}
|
|
|
|
return err
|
|
}
|