mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
23 lines
407 B
Go
23 lines
407 B
Go
|
package testutil
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// WaitTimeout will wait for a WaitGroup to resolve within a timeout interval.
|
||
|
// Returns true if the waitgroup exceeded the timeout.
|
||
|
func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
|
||
|
ch := make(chan struct{})
|
||
|
go func() {
|
||
|
defer close(ch)
|
||
|
wg.Wait()
|
||
|
}()
|
||
|
select {
|
||
|
case <-ch:
|
||
|
return false
|
||
|
case <-time.After(timeout):
|
||
|
return true
|
||
|
}
|
||
|
}
|