WaitFor returns true if condition returns true before maxWait. It is checked immediately, and then every checkInterval.
(condition func() bool, maxWait, checkInterval time.Duration)
| 21 | // WaitFor returns true if condition returns true before maxWait. |
| 22 | // It is checked immediately, and then every checkInterval. |
| 23 | func WaitFor(condition func() bool, maxWait, checkInterval time.Duration) bool { |
| 24 | t0 := time.Now() |
| 25 | tmax := t0.Add(maxWait) |
| 26 | for time.Now().Before(tmax) { |
| 27 | if condition() { |
| 28 | return true |
| 29 | } |
| 30 | time.Sleep(checkInterval) |
| 31 | } |
| 32 | return false |
| 33 | } |