1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-14 22:16:00 +02:00
lego/acme/utils.go

34 lines
594 B
Go
Raw Normal View History

package acme
import (
"fmt"
"time"
"github.com/xenolf/lego/log"
)
2016-03-11 05:51:02 +02:00
// WaitFor polls the given function 'f', once every 'interval', up to 'timeout'.
func WaitFor(timeout, interval time.Duration, f func() (bool, error)) error {
log.Infof("Wait [timeout: %s, interval: %s]", timeout, interval)
var lastErr string
2018-10-09 19:03:07 +02:00
timeUp := time.After(timeout)
for {
select {
2018-10-09 19:03:07 +02:00
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()
}
2016-03-11 05:51:02 +02:00
time.Sleep(interval)
}
}