refactor project structure

This commit is contained in:
hdt3213
2021-05-02 14:54:42 +08:00
parent bb9c140653
commit f29298cc68
78 changed files with 140 additions and 140 deletions

38
lib/sync/wait/wait.go Normal file
View File

@@ -0,0 +1,38 @@
package wait
import (
"sync"
"time"
)
type Wait struct {
wg sync.WaitGroup
}
func (w *Wait) Add(delta int) {
w.wg.Add(delta)
}
func (w *Wait) Done() {
w.wg.Done()
}
func (w *Wait) Wait() {
w.wg.Wait()
}
// return isTimeout
func (w *Wait) WaitWithTimeout(timeout time.Duration) bool {
c := make(chan bool)
go func() {
defer close(c)
w.wg.Wait()
c <- true
}()
select {
case <-c:
return false // completed normally
case <-time.After(timeout):
return true // timed out
}
}