Handle possible error in WaitForSpecific func
In some situations we need to be aware of errors to basically return it rather than polling again and angain until the timeout. Signed-off-by: Guillaume Giamarchi <guillaume.giamarchi@gmail.com>
This commit is contained in:
@@ -94,9 +94,13 @@ func CopyFile(src, dst string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func WaitForSpecific(f func() bool, maxAttempts int, waitInterval time.Duration) error {
|
||||
func WaitForSpecificOrError(f func() (bool, error), maxAttempts int, waitInterval time.Duration) error {
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
if f() {
|
||||
stop, err := f()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if stop {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(waitInterval)
|
||||
@@ -104,6 +108,12 @@ func WaitForSpecific(f func() bool, maxAttempts int, waitInterval time.Duration)
|
||||
return fmt.Errorf("Maximum number of retries (%d) exceeded", maxAttempts)
|
||||
}
|
||||
|
||||
func WaitForSpecific(f func() bool, maxAttempts int, waitInterval time.Duration) error {
|
||||
return WaitForSpecificOrError(func() (bool, error) {
|
||||
return f(), nil
|
||||
}, maxAttempts, waitInterval)
|
||||
}
|
||||
|
||||
func WaitFor(f func() bool) error {
|
||||
return WaitForSpecific(f, 60, 3*time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user