mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-14 12:00:05 +00:00
26 lines
399 B
Go
26 lines
399 B
Go
package testutil
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
func SelectWithTimeout(ch <-chan struct{}, timeout time.Duration) bool {
|
|
select {
|
|
case <-ch:
|
|
return true
|
|
case <-time.After(timeout):
|
|
return false
|
|
}
|
|
}
|
|
|
|
func WaitWithTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
|
|
done := make(chan struct{})
|
|
go func() {
|
|
defer close(done)
|
|
wg.Wait()
|
|
}()
|
|
|
|
return SelectWithTimeout(done, timeout)
|
|
}
|