mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-21 16:09:59 +08:00
remove local network/range
This commit is contained in:
@@ -1,29 +1,4 @@
|
||||
package ncutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
)
|
||||
|
||||
// CheckInInterval - the interval for check-in time in units/minute
|
||||
const CheckInInterval = 1
|
||||
|
||||
// BackOff - back off any function while there is an error
|
||||
func BackOff(isExponential bool, maxTime int, f interface{}) (interface{}, error) {
|
||||
// maxTime seconds
|
||||
startTime := time.Now()
|
||||
sleepTime := time.Second
|
||||
for time.Now().Before(startTime.Add(time.Second * time.Duration(maxTime))) {
|
||||
if result, err := f.(func() (interface{}, error))(); err == nil {
|
||||
return result, nil
|
||||
}
|
||||
time.Sleep(sleepTime)
|
||||
if isExponential {
|
||||
sleepTime = sleepTime << 1
|
||||
}
|
||||
logger.Log(1, "retrying...")
|
||||
}
|
||||
return nil, fmt.Errorf("could not find result")
|
||||
}
|
||||
|
Reference in New Issue
Block a user