Initial commit

This commit is contained in:
2026-05-20 16:13:58 +08:00
commit ceffbe382e
500 changed files with 157469 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package utils
import (
"fmt"
"sync"
)
type WaitGroup struct {
wg sync.WaitGroup
fs []func()
}
func NewWaitGroup() *WaitGroup {
wg := &WaitGroup{}
wg.fs = make([]func(), 0)
return wg
}
func (w *WaitGroup) Add(f ...func()) *WaitGroup {
if w == nil {
panic("WaitGroup can not be null\n")
}
if w.fs == nil {
panic("WaitGroup may be not init\n")
}
w.fs = append(w.fs, f...)
return w
}
func (w *WaitGroup) RunWaits() {
w.wg.Add(len(w.fs))
for _, f := range w.fs {
go func(wg *sync.WaitGroup, fn func()) {
defer func() {
if err := recover(); err != nil {
fmt.Printf("%v\n", err)
}
wg.Done()
}()
fn()
}(&w.wg, f)
}
w.wg.Wait()
}