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,10 +111,7 @@ func For(ctx context.Context, rate time.Duration, cb func() (bool, error)) error ...@@ -111,10 +111,7 @@ func For(ctx context.Context, rate time.Duration, cb func() (bool, error)) error
defer tick.Stop() defer tick.Stop()
for { for {
select { // Perform the first check before any waiting.
case <-ctx.Done():
return ctx.Err()
case <-tick.C:
done, err := cb() done, err := cb()
if err != nil { if err != nil {
return err return err
...@@ -122,6 +119,12 @@ func For(ctx context.Context, rate time.Duration, cb func() (bool, error)) error ...@@ -122,6 +119,12 @@ func For(ctx context.Context, rate time.Duration, cb func() (bool, error)) error
if done { if done {
return nil return nil
} }
select {
case <-ctx.Done():
return ctx.Err()
case <-tick.C:
// Allow loop to continue for next retry
} }
} }
} }
......
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