e7a90b9471
- chore: update dependencies: use version with go modules. - chore: remove dep. - chore: update backoff imports. - chore: init go module. - chore: update CI. - chore: mod v3 - chore: update docker image.
33 lines
614 B
Go
33 lines
614 B
Go
package wait
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/go-acme/lego/v3/log"
|
|
)
|
|
|
|
// For polls the given function 'f', once every 'interval', up to 'timeout'.
|
|
func For(msg string, timeout, interval time.Duration, f func() (bool, error)) error {
|
|
log.Infof("Wait for %s [timeout: %s, interval: %s]", msg, timeout, interval)
|
|
|
|
var lastErr string
|
|
timeUp := time.After(timeout)
|
|
for {
|
|
select {
|
|
case <-timeUp:
|
|
return fmt.Errorf("time limit exceeded: last error: %s", lastErr)
|
|
default:
|
|
}
|
|
|
|
stop, err := f()
|
|
if stop {
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
lastErr = err.Error()
|
|
}
|
|
|
|
time.Sleep(interval)
|
|
}
|
|
}
|