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