WaitTimeout waits until the WaitGroup counter is zero or timeout. It returns true if timed out.
(timeout time.Duration)
| 28 | // WaitTimeout waits until the WaitGroup counter is zero or timeout. |
| 29 | // It returns true if timed out. |
| 30 | func (w *Wait) WaitTimeout(timeout time.Duration) bool { |
| 31 | c := make(chan bool, 1) |
| 32 | go func() { |
| 33 | defer close(c) |
| 34 | w.wg.Wait() |
| 35 | c <- true |
| 36 | }() |
| 37 | select { |
| 38 | case <-c: |
| 39 | return false |
| 40 | case <-time.After(timeout): // complete normally |
| 41 | return true // timed out |
| 42 | } |
| 43 | } |