github.com/prysmaticlabs/prysm@v1.4.4/shared/testutil/wait_timeout.go (about) 1 package testutil 2 3 import ( 4 "sync" 5 "time" 6 ) 7 8 // WaitTimeout will wait for a WaitGroup to resolve within a timeout interval. 9 // Returns true if the waitgroup exceeded the timeout. 10 func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool { 11 ch := make(chan struct{}) 12 go func() { 13 defer close(ch) 14 wg.Wait() 15 }() 16 select { 17 case <-ch: 18 return false 19 case <-time.After(timeout): 20 return true 21 } 22 }