Commit 99fbd21d authored by Adrian Sutton's avatar Adrian Sutton

op-e2e: Modify wait to check before waiting

Avoids wasting time waiting when the condition is already met.
parent 0b492be0
...@@ -111,17 +111,20 @@ func For(ctx context.Context, rate time.Duration, cb func() (bool, error)) error ...@@ -111,17 +111,20 @@ func For(ctx context.Context, rate time.Duration, cb func() (bool, error)) error
defer tick.Stop() defer tick.Stop()
for { for {
// Perform the first check before any waiting.
done, err := cb()
if err != nil {
return err
}
if done {
return nil
}
select { select {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return ctx.Err()
case <-tick.C: case <-tick.C:
done, err := cb() // Allow loop to continue for next retry
if err != nil {
return err
}
if done {
return nil
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment