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
defer tick.Stop()
for {
// Perform the first check before any waiting.
done, err := cb()
if err != nil {
return err
}
if done {
return nil
}
select {
case <-ctx.Done():
return ctx.Err()
case <-tick.C:
done, err := cb()
if err != nil {
return err
}
if done {
return nil
}
// 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