mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-13 01:18:09 -05:00
* move testutil * util pkg * build * gaz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
23 lines
403 B
Go
23 lines
403 B
Go
package util
|
|
|
|
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
|
|
}
|
|
}
|