mirror of
https://github.com/Luzifer/rootzone.git
synced 2024-11-09 16:30:05 +00:00
27 lines
342 B
Go
27 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
|
||
|
}
|